This pr adds support for multiple forms within one Crud.
There will be a route for every method that gets the Ignite\Curd\CrudShow
class as the first parameter. The method name will be the slug. Except for the show method, this is reached directly without slug.
The routes for the following example would be:
admin/posts
Showing the page configured in Page::index
.
admin/posts/1
Showing the page configured in Page::show
.
admin/posts/1/foo
Showing the page configured in Page::foo
.
class PostConfig extends CrudConfig
{
public function routePrefix()
{
return "posts";
}
public function index(CrudIndex $page)
{
//
}
public function show(CrudShow $page)
{
//
}
public function foo(CrudShow $page)
{
//
}
}
Redirect To The Correct Form From Index Table
You may want to redirect the user, when clicking on the index table item, to a certain form depending on the model. This can be achived by specifying returning this form in the getFormNameFor
method in your crud config:
The following example would redirect the user to the foo
form, whenever the type attribute equals foo
, otherwise the default form is used:
/**
* Get the form name for the given Model.
*
* @param Model $model
* @return string
*/
public function getFormNameFor($model)
{
if ($model->type == 'foo') {
return 'foo';
}
return 'show';
}
Create/Update Only
You may now use a form for updating or creating only.
Whenever the method requires the Ignite\Crud\CrudShow
class there will be a route to both the update and create view. However when the classes Ignite\Crud\CrudCreate
or Ignite\Crud\CrudUpdate
are type hinted. Only the associated routes will be present.
Create Only
use Ignite\Crud\CrudCreate;
public function show(CrudCreate $page)
{
//
}
Update Only
use Ignite\Crud\CrudUpdate;
public function show(CrudUpdate $page)
{
//
}