Generating Models

Generating a Model and Its Companion Classes

php artisan make:model Coupon -mf wrote app/Models/Coupon.php, a migration and a factory. Other flags add -s a seeder (Migrations and Seeders), -crR a resource controller with form requests, --policy (Authorization), -p a pivot model (Custom Pivot Models), --pest a test, and -a nearly everything. The section's other classes came from make:enum OrderStatus --string, make:observer ProductObserver --model=Product, make:scope ExcludeCancelledScope and make:cast AsMoney. One trap: make:enum writes into app/Enums only if that directory exists, otherwise into app/. model:show reads the live table and the class together, catching casts that name no column:

Output of 94
$ php artisan model:show Order
...
  Attributes ..................................................... type / cast
  id increments, unique ................................... int unsigned / int
  customer_id fillable .......................................... int unsigned
  status fillable  enum('pending','paid','shipped','cancelled') / App\Enums\OrderStatus
  ordered_at ............................................. datetime / datetime
...