Laravel Artisan Command to Create Migration and Model Example
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...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Laravel Migration Add Column After Column Example
- Laravel Migration Default Value Current Timestamp Example
- How to Add Custom Attribute in Laravel Model?
- Get Array of Ids from Eloquent Models in Laravel
- How to Run Migration and Seeder on Laravel Vapor?
- How to Change Column Length using Laravel Migration?
- How to Update Enum Value in Laravel Migration?
- Laravel Migration Add Comment to Column Example
- Laravel Migration Custom Foreign Key Name Example
- How to Remove Column from Table in Laravel Migration?
- How to Change Column Name and Data Type in Laravel Migration?
- How to Create Table using Migration in Laravel?
- How to disable model timestamps in Laravel?
- How to Get Table Name from Model in Laravel?