Hi,
In this tutorial, I will explain you how to create model in laravel using command.we will implement a how to create model in laravel using artisan command. We will look at example of Make Model in Laravel.
You can use this artisan command with laravel 6, laravel 7, laravel 8, laravel 9, and laravel 10 versions.
As Laravel developers, always need to create an model for database table access. using model you can easily get, insert, edit and delete record in database table.laravel provides artisan command make:model to create model for your database table.
So, let’s see the below command to create a model and implement code.
How to Create Model Laravel Artisan Command
You can create Category model using below Command
php artisan make:model Category
app/Models/Category.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Category extends Model
{
use HasFactory;
}
?>
Then you add $fillable variable with column name.
How to Create Model with Migration Using Laravel Artisan Command:
You can also create model with migration using –migration option. Let ‘see example below command.
php artisan make:model Category --migration
I hope this tutorial can help you…