Rapyd is a simple package for laravel with the aim to let you develop crud interfaces in few lines of code. Few widgets: tables, grids, forms with simple syntax, simple behavior, simple output.
Initiate
$filter = DataFilter::source(Article::with('author','categories'));
Add attributes
$filter->attributes(array("class"=>"form"));
Autocomplete tag
$filter->add('categories.categoryName','Categories','tags');
Checkbox
$filter->add('live','Live Info','checkbox');
Free text search
$filter->add('email_address','Email Address', 'text');
Date range
$filter->add('publication_date','publication date','daterange')->format('m/d/Y', 'en');
Buttons
$filter->submit('search');
$filter->reset('reset');
$filter->build();
$grid = DataGrid::source(TableModel::with("AnotherTableMethodFromTableModel"));
$grid = DataEdit::source(new TableModel);
$grid->add(data,heading,orderby field);
Field | Explanation | |
---|---|---|
$grid->add(title); |
eloquent field | |
$grid->add(category.name); |
relationshop field | |
$grid->add({{$title}}) |
eloquent field | |
$grid->add($row->title) |
eloquent field | |
$grid->add($row->method()) |
eloquent method |
->insertValue('1');
$grid->add('{{ implode(", ", $categories->lists("categoryName")) }}','Categories?);
$grid = DataGrid::source(TableModel::with("AnotherTableMethodFromTableModel"));
$grid->add({{$AnotherTableMethodFromTableModel->id}},"Id");
Use the ampersand @
$grid->add('{{@$row->user->email}}','User');
$grid->add('custom','Custom')->cell(function ($value) {
// you can do for example format $value and/or
return 'custom.. code or view';
});
or using blade syntax / php code
$grid->add('{{ strtoupper($fieldname) }}','Custom');
$grid->add('body', 'Body')->filter('strip_tags|substr[0,20]'); //filters
$grid->add('body|strip_tags|substr[0,20]','Body'); //inline filters
$grid->add('ucfirst(substr( {{ $body }}, 0,100))', 'Body'); //inline blade
/and closure on value
$grid->add('body', 'Body')->cell( function ($value) {
return substr(strip_tags($value), 0, 20);
});
For example view comments link if status is 2,3 or 5:
$grid->add('status','Options')->cell( function( $value, $row) {
return (in_array($value->id,[2,3,5])) ? '<a href="/engage/edit?id=' . $row->id . '">View Comments</a>' : '';
});
Note $row
callback was added in 2.2.1
- if you don't have the latest version you'll need to update the source code (not recommended but if you're stuck on earlier Laravel you won't have much choice:
+
+ //cell closure
+ $grid->add('revision','Revision')->cell( function( $value, $row) {
+ return ($value != '') ? "rev.{$value}" : "no revisions for art. {$row->id}";
+ });
+
https://github.com/zofe/rapyd-laravel/commit/62e87122b21366ed7595eb090b27cd54992887b8
$grid->row(function ($row) {
if ($row->cell('id')->value == 20) {
$row->style("background-color:#CCFF66");
} elseif ($row->cell('id')->value > 15) {
$row->cell('title')->style("font-weight:bold");
$row->style("color:#f00");
}
});
$grid->orderBy('queue_id','desc');
$grid->paginate(10);
Field | Parameters | Example | ||||
---|---|---|---|---|---|---|
Text | field name, label, type | $edit->add('title','Title', 'text'); |
||||
Checkbox | field name, label, type | $edit->add('public','Public','checkbox'); |
Checkbox | field name, label, type | $edit->add('public','Public','checkbox'); |
|
Checkbox group | $edit->add('categories','Categories','checkboxgroup')->options(Category::lists("name", "category_id")->all()); |
|||||
Radiobox | $edit->add('gender','Gender','radiogroup')->option('F','Female')->option('M','Male'); |
|||||
Textarea | $form->add('body','Body', 'textarea') |
|||||
Redactor Textarea | $form->add('body','Body', 'redactor'); |
|||||
Textarea | $form->add('body','Body', 'textarea') |
|||||
Textarea | $form->add('body','Body', 'textarea') |
|||||
File upload | $form->add('download','Attachment', 'file')->rule('mimes:pdf')->move('uploads/pdf/'); |
|||||
Image upload | $form->add('photo','Photo', 'image')->move('uploads/images/')->preview(80,80); |
|||||
Date | $form->add('publication_date','pub.date','date')->format('d/m/Y', 'it'); |
|||||
Date Range | $filter->add('publication_date','pub.date','daterange')->format('d/m/Y', 'it'); |
|||||
Simple Autocomplete | $form->add('author_id','Author','autocomplete')->options(Author::lists('firstname', 'id')); |
|||||
autocomplete with relation.field to manage a belongsToMany | $form->add('author.fullname','Author','autocomplete')->search(array("firstname", "lastname")); |
|||||
Hidden Fields | $filter->add('myfield','','auto')->insertValue('myvalue'); |
|||||
Hidden Fields | $filter->add('anotherfield','','auto')->updateValue('anothervalue'); |
|||||
Content | $edit->add('author1','Author1','container')->content('edited by: {{ $model->author->fullname }}'); |
|||||
Blade View | path of a blade view with $model injected | $edit->add('options','Author2','container')->view('voting.options'); |
||||
iFrame | $edit->add('id','','iframe')->src('/engage/votingquestions?questionId=' . $questionId); |
->mode('readonly')
->rule('required');
->rule('mimes:pdf')
$edit->remove('image');
$edit->set('s3_path', $s3FilePath);
$ages = array (
'all' => 'All',
'under_18' => 'Under 18',
'over_18' => 'Over 18',
);
$edit->add('age_range','Age range','select')->options($ages);
$age_range = $request->input('age_range');
Changing url
->move('uploads/images/)->webPath('/uploads')
note: must come after ->move
Moving a file
->move('uploads/images/');
Renaming a file
->move('uploads/images/','customname.jpg');
Preview
$form->add('photo','Photo', 'image')->move('uploads/demo/')->fit(240, 160)->preview(120,80);
Resize $form->add('photo','Photo', 'image')->move('uploads/demo/')->resize(240, 160)->preview(120,80);
Specify web path prefix explicity:
` ->webPath(PATH)`
$form->add('photo','Photo', 'image')->move('uploads/demo/')->image(function ($image) {
// $image is an instance of \Intervention\Image\ImageManagerStatic
// with uploaded image, you can do here something different...
// remember to do also: $image->save('filename');
})->preview(120,80);
$edit->add('image','Image','image')->image(function($image){
$name = $image->filename.time();
$extension = $image->extension;
$image->widen('800',function($constraint){$constraint->upsize();});
$image->save("public/uploads/{$name}_width800.{$extension}");
}
$form = DataForm::source(Article::find(1));
$form->validator = Validator::make(Input::all(), $rules, $messages);
or trigger a customer error server side:
$form->passed(function () use ($form) {
if (someting...) {
$form->error("..mm there is a problem !");
} else {
$form->message("ok saved!");
}
$form->link("/mycontroller/form","back to the form");
});
return Redirect::to(\Zofe\Rapyd\Persistence::get("authors/list"));
Use Eloquent!
Eg default if no value:
protected $attributes = array(
'mainMedia' => '',
'mainImage' => '');
Replace field value:
public function setMainImageAttribute($value)
{
if ($value == null) $this->attributes['mainImage'] = "xxxx";
else $this->attributes['mainImage'] = value;
}
DataEdit saves and then runs this closure:
$edit->saved(function() use ($edit)
{
$form->field('fieldname')->updateValue($mycustomvalue);
$form->model->fieldname = $mycustomvalue;
$form->model->save();
});
Note $form->passed
is an alias for $form->saved
If you see {{$modelname->field}}
in your grid it meams Rapyd wasn't able to connect to your join.