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.

  1. Create a model for your type
php artisan make:model Thing
  1. Make a migration for the model

    1. run php artisan make:migration adds_things_table --create=things.
    2. edit the new migration to add fields to it. See Laravel Schema for column types.
    3. 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

  2. Make a CRUD configuration for your thing

    1. php artisan enso:make:crud Thing
    2. 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

  3. Make a Crud controller

    1. php artisan make:controller Admin/ThingController
    2. Change base class to Yadda\Enso\Crud\Controller
    3. Add protected $crud_name = "thing"
  4. Fill in file config/enso/crud.php for the new datatype.

  5. Add a route to this controller in routes/web.php. You should use the enso middleware to prevent unauthorised access.

    Route::group(['middleware' => 'enso'], function () {
       EnsoCrud::routes('admin/things', 'ThingController', 'admin.things');
    });
    

    More about the middleware

  6. Register a menu item for the admin area in app/Providers/EnsoServiceProvider.php

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