ItSolutionStuff.com

How to Create Model in Laravel using Command?

By Hardik Savani • April 16, 2024
Laravel

Hi Dev,

In this tutorial, I will show you how to create model in laravel using command. you will learn laravel create model command line. In this article, we will implement a how to create model in laravel using artisan. We will look at example of how to create model in laravel using cmd.

You can use this artisan command with laravel 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11 versions.

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

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

Create Model using Laravel Artisan Command:

You can create Post model using below command.

php artisan make:model Post

You will find following code for Post model.

app/Models/Post.php

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;

use Illuminate\Database\Eloquent\Model;

class Post extends Model

{

use HasFactory;

}

Then you add $fillable variable with columns.

Create Model with Migration using Laravel Artisan Command:

You can also create model with migration using --migration option. let's see below example:

php artisan make:model Post --migration

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 Ajax GET Request Example Tutorial

Read Now →

Laravel React JS Form Validation Example

Read Now →

Laravel Cookies - Get, Set, Delete Cookie Example

Read Now →

How to Use Enum in Laravel?

Read Now →

FCM Push Notification in Laravel Example

Read Now →

Laravel React JS CRUD Application Tutorial

Read Now →

Laravel Country State City Dropdown using Ajax Example

Read Now →

How to install and use Image Intervention in Laravel?

Read Now →

How to Create Custom Middleware in Laravel?

Read Now →

How to Automatically Generate Sitemap in Laravel?

Read Now →

Laravel Send Scheduled Emails Tutorial

Read Now →

How to Send Automatic Email in Laravel 9?

Read Now →