Laravel create table migration with model

You can create both a model and migration file to create table structure using a single command. This command will automatically create the model and migration file which is very convenient as compared to creating manually.

Answers 1
  • Create project table with model and migration

    // Create project model with migration 
    php artisan make:model Project --migration
    // Add columns to project migration file under - database\migrations\<2021_04_21_125826>_create_projects_table.php
    Schema::create('projects', function (Blueprint $table) {
    // Run migrate command to create table structure
    php artisan migrate

    First you have to run artisan command with php artisan make:model Project --migration. This command will create a model and migration for your table structure. After that you can add columns to the migration file and run the php artisan migrate command.

  • Back to code snippet queries related laravel