1. Home
  2. Docs
  3. laravel
  4. “php artisan make:&...
  5. artisan make:model

artisan make:model

PURPOSE

  • typically there will be a Model for each table in the database
  • while the Migration defines the fields in a table, the Model will define how to interact with the table. E.g. updating a database record might imply some calculations, some checks and only then database update command.

USAGE

>php artisan make:model Widget
 
 Usage:
   make:model [options] [--] <name>
 
 Arguments:
   name                  The name of the class
 
 Options:
   -a, --all             Generate a migration, factory, and resource controller for the model
   -c, --controller      Create a new controller for the model
   -f, --factory         Create a new factory for the model
       --force           Create the class even if the model already exists
   -m, --migration       Create a new migration file for the model
   -s, --seed            Create a new seeder file for the model
   -p, --pivot           Indicates if the generated model should be a custom intermediate table model
   -r, --resource        Indicates if the generated controller should be a resource controller
   -h, --help            Display this help message
   -q, --quiet           Do not output any message
   -V, --version         Display this application version
       --ansi            Force ANSI output
       --no-ansi         Disable ANSI output
   -n, --no-interaction  Do not ask any interactive question
       --env[=ENV]       The environment the command should run under
   -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug 

PARAMETERS

--migration / -m

Also create a new migration file for the model.

--controller / -c

Also create a new controller for the model.

--resource / -r

Indicates if the generated controller should be a resource controller.

--migration --controller --resource / -mcr

Create a Model, a Migration, and a Resource Controller

--factory / -f

Create a new factory for the model.

--all / -a

Generate all of the above: a migration, factory, and resource controller for the model.

--force

Create the class even if the model already exists.

--pivot

Indicates if the generated model should be a custom intermediate table model.

OUTPUT

Output will be by default in app/:
app/Widget.php

Another possibility is to store them together in app/Models:
app/Models/Widget.php

Reference: https://laravel.com/docs/6.x/eloquent

Tags , ,