Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

DataEdit

Felice Ostuni edited this page Oct 1, 2015 · 18 revisions

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')..

return $edit->view('crud', compact('edit'));
   #crud.blade.php
  {!! $edit !!}

routing only a dataedit

You can use "implicit controllers" http://laravel.com/docs/5.1/controllers#implicit-controllers
but you can also route single dataedit using:

Route::any('/something/edit', 'SomethingController@edit');
// note "any" is needed because  dataedit manage 
// "get","post","patch" and "delete" http methods

adding fields

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

buttons

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.

custom buttons

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.

back action

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).

view render

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.

Clone this wiki locally