Creating Modules with the Console

textstem:make:module generates a working admin section for a new model.

1. Create the table first

The generator reads the live database table: a slug column gets the model Sluggable support, and the filter and action builders are filled from the real columns. Without the table you silently get a slug-less model and empty builders, so migrate first:

php artisan make:migration create_tracks_table
# define the table, then
php artisan migrate

2. Run the generator

php artisan textstem:make:module Tracks

The name is made plural for the module and singular for the model. For Tracks this creates:

File What it is
app/Models/Track.php The model (HasFactory, Textstem's Searchable search scopes, and Sluggable if the table has a slug column)
app/Http/Controllers/TrackController.php A resource controller, plus a duplicate() action
app/Policies/TrackPolicy.php A policy checking list tracks, view tracks, create tracks, update tracks and delete tracks
app/Http/Requests/TrackStoreRequest.php, TrackUpdateRequest.php Form requests to fill in
app/Livewire/Tables/TrackTable.php The admin list, a Textstem table
app/Domain/Tracks/Config/TrackActionBuilder.php, TrackFilterBuilder.php The bulk actions and filters for the table
resources/views/admin/tracks/index.blade.php, create, edit, form-inputs The admin views

No migration and no routes are created.

3. Finish it by hand

  1. Routes. The command prints the line to add. Put it inside an admin route group (see Modules):

    Route::resource('tracks', TrackController::class);
    
  2. Register the policy, because the package's policy lookup won't find it:

    Gate::policy(\App\Models\Track::class, \App\Policies\TrackPolicy::class);
    
  3. Make the controller and policy agree. The generated controller calls authorize('edit track', …), 'update track' and 'delete track' (singular), which match neither a policy method nor the plural permissions. Change them to the policy methods, for example $this->authorize('update', $track).

  4. Create the permissions the policy checks, with a seeder or in Admin → Roles.

  5. Add a menu entry under modules in config/textstemapp.php (see Modules).

esc