The Laravel create migration and model command are the main topics of this lesson. You’ll learn how to use CMD to create migrations and models for Laravel. We will assist you by providing a model and migration example created by a laravel artisan. It is a straightforward illustration of a migration and model made with PHP. Let’s begin by running the create migration command in the Laravel model.
This is just a quick suggestion, but you can use the artisan command to build migration and models simultaneously. We will create a model with migration using the php artisan make command. Let’s look at the commands now.
php artisan make:model mytable --migration
php artisan make:model mytable -m
You will see the following model and migration.
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class mytable extends Model
{
use HasFactory;
}
<?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('mytables', function (Blueprint $table) {
$table->id();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('mytables');
}
};
I’m Abhishek, a DevOps, SRE, DevSecOps, and Cloud expert with a passion for sharing knowledge and real-world experiences. I’ve had the opportunity to work with Cotocus and continue to contribute to multiple platforms where I share insights across different domains:
-
DevOps School – Tech blogs and tutorials
-
Holiday Landmark – Travel stories and guides
-
Stocks Mantra – Stock market strategies and tips
-
My Medic Plus – Health and fitness guidance
-
TrueReviewNow – Honest product reviews
-
Wizbrand – SEO and digital tools for businesses
I’m also exploring the fascinating world of Quantum Computing.
[…] Create Migration and Model by Artisan Command in Laravel […]