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:

bash
php 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:

bash
php artisan make:migration create_customers_profiles_table