Skip to main content
Tutorial Free

How to create migration file with Make:model command

October 20, 2015
1 min read
Recently I've found out a nice little way to speed up generating of database stuff - I used to use make:migration and make:model Artisan commands separately. Apparently, they can be combined into one. So if you run a command like this:
artisan make:model Books -m
It will create a migration file automatically for you. The magic is in -m parameter. The whole thing looks like this:
artisan make:model Books -m
Model created successfully.
Created Migration: 2015_10_19_012129_create_books_table
And the result is that we have two files generated: app/Books.php:
namespace App;

use Illuminate\Database\Eloquent\Model;

class Books extends Model
{
    //
}
And database/migrations/2015_10_19_012129_create_books_table.php:
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateBooksTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('books', function (Blueprint $table) {
            $table->increments('id');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('books');
    }
}
Notice that migration file comes with automatically suggested auto_increment field and timestamps. Isn't that sweet of Laravel? Constantly saving our time, second by second.

Enjoyed This Tutorial?

Get access to all premium tutorials, video and text courses, and exclusive Laravel resources. Join our community of 10,000+ developers.

Recent Courses

Laravel Coding with AI Agents: Cursor, Claude Code, Codex

5 lessons
1 h 01 min

Laravel Modules and DDD

16 lessons
1 h 59 min

Filament 4 From Scratch

28 lessons
2 h 25 min

Comments & Discussion

No comments yet…

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.