-
Notifications
You must be signed in to change notification settings - Fork 297
DataEdit
DataEdit extends DataForm, it's a full CRUD application for given Entity.
It has status (create, modify, show) and actions (insert, update, delete)
It detect status by simple query string semantic:
/dataedit/uri empty form to CREATE new records
/dataedit/uri?show={record_id} filled output to READ record
/dataedit/uri?modify={record_id} filled form to UPDATE a record
/dataedit/uri?delete={record_id} perform record DELETE
...
//simple crud for Article entity
$edit = DataEdit::source(new Article);
$edit->link("article/list","Articles", "TR")->back();
$edit->add('title','Title', 'text')->rule('required');
$edit->add('body','Body','textarea')->rule('required');
$edit->add('download','Attachment', 'file')
->rule('mimes:pdf')
->move('uploads/pdf/');
$edit->add('photo','Photo', 'image')
->rule('mimes:jpeg')
->move('uploads/images/')
->fit(320,240);
$edit->add('author.fullname','Author','autocomplete')
->search(array('firstname','lastname'));
//you can also use shorthand methods, add{Type}(...
$edit->addText('title','Title');
$edit->addTextarea('body','Body')->rule('required');
//you can also use smart syntax, ->{type}(... ):
$edit->textarea('title','Title');
$edit->autocomplete('author.name','Author')
->search(array('firstname','lastname'));
return $edit->view('crud', compact('edit'));
#crud.blade.php
{{ $edit }}
By default a DataEdit is empty, without fields. Ok you give a valid model source but it leave you to add only fields you need, check the field list
As you see you can append fields and links, while the "buttons" (save, undo, delete, etc..) and messages (like delete confirmation) are fully managed by dataedit.
In demos we use "link" method on dataedit to build a back_link to a datagrid.
parameters are: ->link($uri, $label, $position)
$uri and $label are quite simple to understand, the last parameter $position is the position where the button will appear: "TR","BL","BR" (top right, bottom left, bottom right). TL is not valid because this position is reserved to show widget label.
You can add a ->back()
or more specific ->back('do_delete|update')
to a link if you want to auto-pull back after all actions (or after some of these).
note: we use $edit->view method instead View::make for a reason: DataEdit must manage redirects. With other widgets you should use View facade as default.
presentation
editing