Laravel Artisan Command to Create Migration and Model Example

By Hardik Savani November 5, 2023 Category : Laravel

Hey Artisan,

This tutorial is focused on laravel create migration and model command. you'll learn laravel create migration and model using cmd. we will help you to give an example of laravel artisan create migration and model. It's a simple example of php artisan make migration and model. Let's get started with create migration with model laravel command.

This is a small tips, you can create migration and model together using artisan command. we will use php artisan make command to generate model with migration. so, let's see the commands.

Artisan Command to Create Model and Migration:

php artisan make:model Setting --migration

php artisan make:model Setting -m

You will see the following model and migration.

app/Models/Setting.php

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;

use Illuminate\Database\Eloquent\Model;

class Setting extends Model

{

use HasFactory;

}

database/migrations/create_settings_table.php

<?php

use Illuminate\Database\Migrations\Migration;

use Illuminate\Database\Schema\Blueprint;

use Illuminate\Support\Facades\Schema;

return new class extends Migration

{

/**

* Run the migrations.

*/

public function up(): void

{

Schema::create('settings', function (Blueprint $table) {

$table->id();

$table->timestamps();

});

}

/**

* Reverse the migrations.

*/

public function down(): void

{

Schema::dropIfExists('settings');

}

};

I hope it can help you...

Tags :
Shares