Skip to content

Model Generator

The Model Generator Command, will create a new Model for the provided Module with a basic boilerplate code. If you want to create a new Profile Model, for the Customer Module, you can run the following command:

php artisan modular:make-model Customer Profile

Or if you are using Laravel Sail, run:

sail artisan modular:make-model Customer Profile

And a new file will be created at modules/Customer/Models/Profile.php.

Suggested Model Traits

The new created Model will have the correct Module Namespace and will import some suggested traits, like:

  • Illuminate\Database\Eloquent\SoftDeletes so the data of your Model will be soft-deleted instead of being permanently deleted from the database
  • Modular\Modular\Traits\Searchable so you can easily integrate search for data in your Model, using a Laravel Query Scope in your Model
  • Modular\Modular\Traits\ActivityLog that under the hood uses Spatie's Laravel-activitylog package, so your Model can keep track and log events like created, updated, deleted, referencing the context and user that triggered the event (for auditing purposes, etc)

The Model Table

You'll need to create a migration for your new model, using the default Laravel command:

php artisan make:migration create_customers_profiles_table

Or if you are using Laravel Sail, run:

sail artisan make:migration create_customers_profiles_table