Home Laravel How to Create Model in Laravel using Command?

How to Create Model in Laravel using Command?

by Shahriar Sagor
Create Model in Laravel

Today now in this tutorial, I will show you an example of how to create the model in laravel application by using command. From here you will learn about laravel create model command line. So In this article, i will implement a how to create the model in laravel by using artisan. Here i will look at example of how to create model in laravel by using cmd.

We can also use this artisan command with laravel 6, laravel 7, laravel 8 and laravel 9 any versions.

As Laravel developers, we always have to create an eloquent model for the database table access. By using the laravel model we can easily get, insert, edit and delete records of a table. Here, Now in this post, I will give you a quick tips to create a model by using the laravel artisan command. In laravel provides the artisan make:model command to create the model for your database table.

So, let’s start and see the below command to create a model and model with code.

Create Model using Laravel Artisan Command:

You can easily create Post model by using below command.

php artisan make:model Post

We will find following code for Post model.


namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
    use HasFactory;

Then we have add $fillable variable with columns.

Create Model with Migration using Laravel Artisan Command:

We can also create the model with migration by using –migration option. let’s see the below example:

php artisan make:model Post --migration

Read Also: php artisan serve not working in Laravel

Thanks for read. I hope it help you. For more you can follow us on facebook


You may also like