Laravel Magazine
Six Artisan Make Flags You're Probably Not Using

Six Artisan Make Flags You're Probably Not Using

Eric Van Johnson ·

Most of us learned php artisan make:model Post early and never looked much further at what the make commands can actually do. That's a shame, because a lot of the follow-up busywork, "now let me also make a migration, a factory, a policy, and a resource", is already built into flags on the same command. Here are six worth adding to muscle memory.

1. make:model with -a for "give me everything"

php artisan make:model Post -a

The -a (all) flag generates the model plus a migration, factory, seeder, policy, controller, form requests, and resource controller in one shot. If you're starting a new Eloquent model and you know you'll need most of the standard scaffolding anyway, this beats running five separate commands and then remembering which one you forgot.

If you only want a subset, the individual flags are -m (migration), -f (factory), -s (seeder), -p (policy), -c (controller), and -r (adds resource methods to the controller). Combine whichever you need:

php artisan make:model Post -mfc

2. make:controller --resource --model

php artisan make:controller PostController --resource --model=Post

--resource scaffolds the seven standard CRUD methods (index, create, store, show, edit, update, destroy). Adding --model=Post goes a step further and type-hints Post in every method that should receive one, so show(Post $post) and update(Request $request, Post $post) come pre-wired for route model binding instead of you adding the type hints by hand afterward.

3. make:migration with --table for renaming intent

php artisan make:migration add_status_to_posts_table --table=posts

This doesn't change what code gets generated dramatically, but it does pre-fill the Schema::table('posts', ...) call in the generated migration instead of the default Schema::create() stub, saving you the "oh right, this is an alter migration not a create migration" edit every time.

4. make:factory with --model when the name doesn't match

Artisan guesses the model a factory belongs to based on the factory's name, PostFactory maps to Post automatically. When your naming doesn't follow that convention, or you want a second factory for the same model with different defaults, be explicit:

php artisan make:factory ArchivedPostFactory --model=Post

5. make:test with --pest

If your project has switched to Pest but muscle memory still types make:test, this flag keeps you from generating a PHPUnit-style class-based test by mistake:

php artisan make:test PostSearchTest --pest

Worth knowing: once your phpunit.xml (or pest.config.php setup) is fully Pest-based, Laravel actually detects that and defaults make:test to Pest's functional style automatically. The explicit flag matters most on projects mid-migration between the two, or where you want to be certain regardless of project defaults.

6. make:model --pivot for pivot models

php artisan make:model RoleUser --pivot

If you're upgrading a plain belongsToMany pivot table into a full pivot model, so you can add custom methods or casts to the pivot record itself, this flag generates a model extending Pivot instead of the standard Model base class, with the right defaults for a pivot table already in place (no auto-incrementing id, timestamps handled appropriately for a pivot context).

The pattern worth remembering

Almost every make: command has a handful of flags like this, and php artisan make:model --help (swap in any command name) will list every option for the specific command you're running. It's worth a five minute skim through the ones you use most often, chances are decent there's a flag quietly doing the follow-up step you've been doing by hand.

Stay Updated

Subscribe to our newsletter

Get latest news, tutorials, community articles and podcast episodes delivered to your inbox.

Weekly articles
We send a new issue of the newsletter every week on Friday.
No spam
We'll never share your email address and you can opt out at any time.