SarahS's avatar
Level 12

Creating models with controllers, factories and migrations

I've been following the courses to learn Laravel and I've learnt that to create a controller with a model I do:

php artisan make:controller Posts -r -m Post

but if I want to do a migration with a factory then I need to add that to a model so I shouldn't add -m above but do:

php artisan make:model Post -m -f

I've been doing some searching and I have found that to get all 4 I should do:

php artisan make:model Post -crm

Is this right and is this the best way of doing it?

0 likes
6 replies
rwdevguy's avatar

It's a perfectly fine way to do it. Is there anything you don't like about this approach?

Nakov's avatar
Nakov
Best Answer
Level 73

You can run php artisan help make:model it will give you all the possible options, so in your case I believe you can achieve it by running:

php artisan make:model Post -a
1 like
SarahS's avatar
Level 12

@ROSSWILSON252 - Hi, thanks for the reply, do you mean the last one is the best way:

php artisan make:model Post -crm

SarahS's avatar
Level 12

@NAKOV - Thanks, I've just run that and the -a should do everything I need then.

Nakov's avatar

@SARAHS74 - If it helped consider marking an answer as the Best Answer it will help others too.

SarahS's avatar
Level 12

@NAKOV - I always do but I wanted to make sure I had finished the conversation before doing that.

Please or to participate in this conversation.