CRUD Types
Enso CRUDs are a combination of:
- A CRUD Config (
Yadda\Enso\Crud\Config) - A model (
Illuminate\Database\Eloquent\Model) (and related database tables) - A controller (
Yadda\Enso\Crud\Controller) - An item in the Enso admin menu
Creating a CRUD
php artisan make:crud MyThing
The Artisan command will create the necessary files and provide you the coded needed for the rest of the setup.
Creating a CRUD Manually
If you don't want to use the Artisan command, you can do the process manually.
- Create a model for your type
php artisan make:model Thing
Make a migration for the model
- run
php artisan make:migration adds_things_table --create=things. - edit the new migration to add fields to it. See Laravel Schema for column types.
- run the migration (must be done in VM if running in one) with
php artisan migrate.
NOTE: Don't forget to make all the correct columns fillable within the model, and set up relationships as you want them
- run
Make a CRUD configuration for your thing
- php artisan enso:make:crud Thing
- TEMP: Remove HasMetaTab references (until command is remade to exclude them)
NOTE: The name you pass this should be singular! ALSO NOTE: You will need to remove HasMetaTab references until this command is remade to exclude them
Make a Crud controller
php artisan make:controller Admin/ThingController- Change base class to
Yadda\Enso\Crud\Controller - Add
protected $crud_name = "thing"
Fill in file
config/enso/crud.phpfor the new datatype.Add a route to this controller in
routes/web.php. You should use theensomiddleware to prevent unauthorised access.Route::group(['middleware' => 'enso'], function () { EnsoCrud::routes('admin/things', 'ThingController', 'admin.things'); });Register a menu item for the admin area in
app/Providers/EnsoServiceProvider.phpSee Admin Menu for more details.
Gotchas
If your CRUD is saving without an error but the data is not being populated in the database, you may need to add the field's name to the fillable array on your model.