Courses

Laravel 11 Eloquent: Expert Level

Customize Model Default Template with Stubs

Summary of this lesson:
- Publishing and customizing model stubs
- Modifying default model template structure
- Removing default traits like HasFactory
- Understanding stub customization options

The default Eloquent Model is generated with a structure as below.

<?php
 
namespace App\Models;
 
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
 
class Post extends Model
{
use HasFactory;
}

And it has a trait HasFactory. What if you want to remove it because you won't use it in the project and want all new Models not to have it?

You can overwrite the default structure by...

The full lesson is only for Premium Members.
Want to access all 28 lessons of this course? (71 min read)

You also get:

  • 69 courses (majority in latest Laravel 11)
  • Premium tutorials
  • Access to repositories
  • Private Discord