Black Friday: coupon FRIDAY24 for 40% off Yearly/Lifetime membership! Read more here

How to create migration file with Make:model command

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.

No comments or questions yet...

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 67 courses (1172 lessons, total 43 h 18 min)
  • 90 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord

Recent New Courses