We have put together a CRUD command. It will set up all the core files necessary to create a well put together CRUD. Routes and Views will need to be added separately given the complexity of some applications.
The files included are:
- model
- controller
- API controller
- handler (service)
- policy
- request
- management (trait for additional route method)
- helpers (trait for manipulating data)
- transformer (for fractal with API)
- views (basic crud views)
- tests (feature and unit examples)
For command help
$ php artisan -h make:crud
First argument is the name of the model. Second Argument is the plural version.
$ php artisan make:crud SalesTerritory SalesTerritories
By default this command will also create a migration for the new model. If you'd prefer to not create the migration use the --no-migration
option.
$ php artisan make:crud SalesTerritory SalesTerritories --no-migration
By default the command will create all of the resources available. If you only need a few resources you may use the --with
option. This will prompt for you to specify which resources you need.
$ php artisan make:crud SalesTerritory SalesTerritories --with
If you wish to create the resources for an API you may use the --api
option. This will generate a base ApiController if one does not exist along with an api specific controller on top of the normal controller for the model.
$ php artisan make:crud SalesTerritory SalesTerritories --api
All of these options may be used in conjunction with one another to produce the desired resources.