ItSolutionStuff.com

Laravel Artisan Command to Create Migration and Model Example

By Hardik Savani • November 5, 2023
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: Laravel
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

Laravel Migration Add Column After Column Example

Read Now →

Laravel Migration Default Value Current Timestamp Example

Read Now →

How to Add Custom Attribute in Laravel Model?

Read Now →

Get Array of Ids from Eloquent Models in Laravel

Read Now →

How to Run Migration and Seeder on Laravel Vapor?

Read Now →

How to Change Column Length using Laravel Migration?

Read Now →

How to Update Enum Value in Laravel Migration?

Read Now →

Laravel Migration Add Comment to Column Example

Read Now →

Laravel Migration Custom Foreign Key Name Example

Read Now →

How to Remove Column from Table in Laravel Migration?

Read Now →

How to Change Column Name and Data Type in Laravel Migration?

Read Now →

How to Create Table using Migration in Laravel?

Read Now →

How to disable model timestamps in Laravel?

Read Now →

How to Get Table Name from Model in Laravel?

Read Now →