rawilk/laravel-stubs
Opinionated Laravel stubs with strict types, fewer docblocks, unguarded models, controllers without a base class, migrations without down methods, and added return type hints. Publish via artisan and optionally keep stubs updated via composer hooks.
Installation:
composer require rawilk/laravel-stubs --dev
Add this to your composer.json to auto-publish stubs on updates (ensure compatibility with Laravel 13.x):
"scripts": {
"post-update-cmd": [
"@php artisan custom-stub:publish --force"
]
}
Publish Stubs:
php artisan custom-stub:publish
This replaces Laravel’s default stubs with the opinionated versions, now fully compatible with Laravel 13.x and PHP 8.5.
First Use Case: Generate a migration to see the changes:
php artisan make:migration create_posts_table --laravel=13
Notice the absence of down() method, declare(strict_types=1), and timestamps by default, now aligned with Laravel 13.x conventions.
Consistent Code Generation:
php artisan make: commands (e.g., make:controller, make:model) to generate files with the package’s opinionated structure.use Illuminate\Foundation\Application;).Type Safety:
declare(strict_types=1) and return type hints where applicable (e.g., in controllers, commands).public function index(): Response
{
return response()->json([]);
}
Simplified Migrations:
down() method, aligning with modern Laravel practices (use php artisan migrate:fresh for resets).public function up(): void
{
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->timestamps();
});
}
Modern Syntax:
use Illuminate\Foundation\Application; in stubs, updated Mailable stubs).public function build(): Mailable
{
return $this->markdown('emails.posts.created')->subject('New Post');
}
Package Development:
composer require --dev rawilk/laravel-stubs orchestra/canvas
composer exec canvas preset package
Configure canvas.yaml for Laravel 13.x:
preset: Rawilk\Stubs\Canvas\Package
namespace: YourPackageNamespace
laravel_version: 13.*
Generate files via:
composer exec canvas make:migration CreatePostsTable --create --laravel=13
Custom Stubs:
resources/stubs/.array_unpack, str_contains).Missing down() in Migrations:
down() methods. If your team relies on rollback logic, manually add it or use php artisan migrate:fresh for testing.Strict Types (PHP 8.5):
declare(strict_types=1) is added globally. Ensure all generated code (e.g., factories, policies) supports PHP 8.5.array_unpack or str_contains in custom stubs.Removed Docblocks:
Namespace Placeholders:
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
Canvas Integration:
orchestra/canvas for package stubs. Misconfigured canvas.yaml may break generation.laravel_version in canvas.yaml to avoid compatibility issues.Laravel 13.x Breaking Changes:
Mailable) may reference deprecated classes. Update custom stubs to use Laravel 13.x equivalents (e.g., Illuminate\Mail\Mailable instead of older imports).resources/stubs/ after running custom-stub:publish.vendor/rawilk/laravel-stubs/stubs/ to resources/stubs/ to customize them for Laravel 13.x.$table->timestamps() by default. Remove if not needed (e.g., for audit tables).resources/stubs/ and update composer.json scripts to republish them.
resources/stubs/model.stub for custom model generation.namespace in stubs for multi-tenant applications.php artisan custom-stub:publish in deployment scripts.
composer dump-autoload after publishing stubs to optimize autoloading.bootstrap/app.php changes) in custom stubs.How can I help you explore Laravel packages today?