Publish and customize Artisan generator stubs using php artisan stub:publish to enforce custom code conventions across your team.
Standard php artisan make:controller or make:model commands generate default framework templates.
Running stub:publish exports these blueprint files to a local stubs/ directory, allowing you to enforce project-specific conventions automatically.
1. Publish Stubs
php artisan stub:publish
This exports all generator stubs into your application root's stubs/ directory.
2. Customize Templates (e.g. stubs/model.stub)
Edit any stub file to enforce strict types, default properties, or custom traits:
<?php
namespace {{ namespace }};
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class {{ class }} extends Model
{
use HasFactory;
// Enforce un-guarded models by default across the team
protected $guarded = [];
}
Key Benefits
- Team Consistency: Every developer running
make:modelormake:controllerreceives the standardized company template. - Zero Friction: Automatically picked up by Artisan without requiring any custom command flags or configuration files.
Related Tips
View all tips →Scaffold Actions, Builders, and Collections with Artisan
Extend your generator commands to scaffold common domain patterns like Actions, Custom Query Builders, and Collections directly via Artisan.
Protect Custom Artisan Commands from AI Agents with Prohibitable
Use Laravel's Prohibitable trait on custom Artisan commands to selectively block AI agents from running destructive domain operations.