Download the PHP package cerebralfart/laravel-crud-controller without Composer
On this page you can find all versions of the php package cerebralfart/laravel-crud-controller. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cerebralfart/laravel-crud-controller
More information about cerebralfart/laravel-crud-controller
Files in cerebralfart/laravel-crud-controller
Package laravel-crud-controller
Short Description An easy way to do your CRUD stuff
License MIT
Informations about the package laravel-crud-controller
Laravel CRUD
An easy way to do your CRUD stuff
Registering routes
The CRUD controller works as a RESTful resource controller, so you can use the following one-liner to register a controller.
This will register the following routes:
Verb | Path | Action | Name |
---|---|---|---|
GET | /users | index | users.index |
GET | /users/create | create | users.create |
POST | /users | store | users.store |
GET | /users/{user} | show | users.show |
GET | /users/{user}/edit | edit | users.edit |
PUT | /users/{user} | update | users.update |
DELETE | /users/{user} | destroy | users.destroy |
If you only need some of these routes, you can use ->only
:
General configuration
Optional configuration
Disabling authentication
While not recommended, it is possible to disable the authorization. This can be done at the controller-level by setting the $authDisabled
property to true, or by passing an array of actions on which it should be disabled.
Customizing authorization error messages
The CRUDController provides default error messages for all routes, but these can be overridden if you want to provide more specific errors.
The easiest way to do so is via the $authErrors
property on the controller.
Alternatively, if you require more fine-grained control of the error message displayed, we recommend customizing this in the policy class.
List models
Filtering
There are two ways to define filters in the CRUDController. All filters are defined as functions, but their interpretation depends on the argument it allows.
Filtering on database level can be done by accepting a Builder
instance, like the filterDraft
below. You can apply any where-clause you'd like to.
Alternatively, you can filter items once they are retrieved from the database, where you can interact with your models as you normally would. See the filterHot
option below.
To activate one or more filters, simply pass their names to the _filter
property in your request. The controller can accept multiple filters simultaneously, in which case they are applied in an AND-like manner.
A default set of filters can be defined using the defaultFilters
property on the controller.
Should you want to invert a filter, e.g. retrieve all non-draft items, you can prefix the filter name in the request with an exclamation mark: _filter=!draft