Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here
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.

Comments & Discussion

No comments yet…