How do I create a model in laravel?

How do I create a model in laravel?

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

How do I create a model in Laravel?

When you first encounter the default User model in an older version of Laravel, it can feel like reading documentation for a system that no longer exists. The class implements specific interfaces and uses traits related to authentication (UserInterface, RemindableInterface) and password hashing (UserTrait). If you are building a new project or working with modern Laravel, that boilerplate is largely obsolete.

To create a model for a table like products without any authentication logic, you do not need to implement those interfaces or use those specific traits. In fact, adding them would only introduce confusion and unnecessary dependencies on the legacy Illuminate\Auth namespace. The core principle of a Laravel model is simplicity: it is an Eloquent class that maps directly to your database table.

You can generate a fresh model using the artisan command:

php artisan make:model Product -mcr

The -mcr flag tells Laravel to create the Model, Migration, and Controller for you. However, focusing strictly on the model, here is what you should expect when you inspect the generated file:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    // The table name is inferred from the class name (snake_case)
    // so you don't need to define $table unless your table is named 'products' specifically.
}

Notice the absence of implements UserInterface or use RemindableTrait. This is intentional. In modern Laravel, authentication concerns are handled by the Auth facade and specific guard configurations, not by forcing every model to implement a user interface. If your table is named products, the $table property defaults to 'products' automatically because Laravel follows the convention of converting the class name from camelCase to snake_case.

You only need to manually set the $table property if you are violating that convention, for example, if your database table is actually named items.

class Item extends Model
{
    protected $table = 'items'; // Explicitly setting the non-conventional name
}

Regarding JSON serialization, older tutorials often included a $hidden property to exclude sensitive data like passwords. While this was critical for the legacy User model where passwords were stored in plain text or hashed differently, modern Laravel handles this via the $fillable and $appends properties, as well as accessors for sensitive fields. For a standard product model, you typically leave these empty unless you have specific serialization requirements.

class Product extends Model
{
    // Define which mass-assignable attributes are allowed
    protected $fillable = ['name', 'price', 'stock_quantity'];
}

The decision to extend Model (or Eloquent in legacy contexts) is the only inheritance requirement. This provides you with database querying capabilities, relationship definitions, and lifecycle hooks like created, updated, and deleted.

If you are using a recent version of Laravel, you might also consider adding $guarded = [] to your model if you strictly want to allow mass assignment for every attribute defined in your migration. This is a trade-off; by default, Laravel guards against mass assignment vulnerabilities by requiring the $fillable property. For most applications, explicitly defining protected $fillable remains the safer and more explicit approach.

For detailed guidance on setting up authentication features correctly without relying on legacy interfaces, you can refer to the official resources provided by https://laravelcompany.com to ensure your security configuration aligns with current best practices.

Our network