82

I'm creating a model on the Laravel 5 with this command:

php artisan make:model Settings

As it shows on the video lessons that as soon as model is created, new migration file also must be created. But, in my situtation, migration is not being created. How can I get the migration generated when model is created?

composer.json:

...
    "require": {
            "php": ">=5.5.9",
            "laravel/framework": "5.1.*"
        },
...
Sarvar Nishonboyev
  • 12,262
  • 10
  • 69
  • 70

8 Answers8

145

I'm guessing your build of L5 is fairly old, as they disabled creating migrations alongside the model creation.

Try running the ff:

php artisan make:model Settings --migration
davsp
  • 2,049
  • 1
  • 14
  • 13
61

Try using this Command

php artisan make:model ModelName -m

OR

php artisan make:model ModelName --migration

It will create model with migration class

ThisDude
  • 111
  • 2
  • 9
Ashish
  • 6,791
  • 3
  • 26
  • 48
  • 5
    It's a little bit of an aside, but there should not be an underscore between Model and Name in terms of conventions. Just making that note since this seems like a question that many beginners would flock to. – helios456 Feb 13 '19 at 02:32
  • @helios456 i put Underscore because people can understand where to put Name of Model Read in side of Bracket [ Model_Name = Name of the model user want he can put anything at the position]. – Ashish Feb 13 '19 at 09:01
  • 4
    Updated and removed the underscore so it won't mislead those who didn't read comment – ThisDude Dec 03 '20 at 18:32
28

Also you can use this command:

    php artisan make:model ModelName -m

and if you wanna make controller for your model, you should write this command :

   php artisan make:model ModelName -mc
   
   // or 

   php artisan make:model ModelName -mcr  //(r: for resource methods)
Hamid Teimouri
  • 462
  • 4
  • 8
20

2020 update:

You can now do:

php artisan make:model ModelName -a

To create a:

  1. model
  2. controller
  3. seeder
  4. migration
  5. factory

All using one command.

Wouter Dorgelo
  • 11,770
  • 11
  • 62
  • 80
13

You can use the make:model flags like;

php artisan make:model Setting -m

enter image description here

Help: php artisan make:model --help

bmatovu
  • 3,756
  • 1
  • 35
  • 37
12

Create Model and Migration :

php artisan make:model Image -m

Create Model, Migration and Controller with resource :

php artisan make:model Image -mcr

Shortcut to generate a model, migration, factory, seeder, policy, controller, and form requests :

php artisan make:model Image --all

Jatniel
  • 1,967
  • 2
  • 19
  • 27
1

It's weird because to skip migration you could use the flag --no-migration. That means that calling php artisan make:model Foo should automatically create everything. Does artisan show any errors? Did you check logs? What Laravel version are you using? 5? 5.1?

Matt Komarnicki
  • 5,198
  • 7
  • 40
  • 92
  • it is latest version, I just yesterday installed and started learning Laravel. Looked at Logs file in storage/logs no any error is showing. Artisan is completing successfully, not showing any error too. – Sarvar Nishonboyev Jul 31 '15 at 07:10
1

If you would like to generate a database migration when you generate the model, you may use the --migration or -m option

php artisan make:model Settings --migration

php artisan make:model Settings -m

Rayees Pk
  • 2,503
  • 1
  • 23
  • 19