spatie/boost-spatie-guidelines
AI-optimized Spatie coding guidelines for Laravel Boost. Installs battle-tested Laravel & PHP standards into your .ai/guidelines folder so AI assistants generate PSR-compliant, convention-driven code (types, naming, control flow, testing) automatically.
Install the package in your Laravel project:
composer require spatie/boost-spatie-guidelines --dev
Run Boost installation:
php artisan boost:install
.ai/guidelines/boost-spatie-guidelines/.Verify integration:
Ask Boost to generate a controller for a User resource:
"Create a Laravel controller for managing users with RESTful routes, following Spatie’s guidelines. Include happy path logic and proper type hints."
Expected output:
snake_case route naming (users).camelCase (storeUser, updateUser).AI-Assisted Development Loop:
"Write a Laravel policy for
Postwith Spatie’s happy path pattern and nullable type hints."
Consistent Codebase Enforcement:
class User extends Model
{
use HasApiTokens, Notifiable;
protected $fillable = [
'name', 'email', 'password',
];
protected $hidden = ['password'];
protected $casts = [
'email_verified_at' => 'datetime',
];
}
snake_case routes + camelCase methods:
Route::post('/users', [UserController::class, 'storeUser']);
Validation and Blade:
"Generate FormRequest for user registration with Spatie’s validation rules." Output:
public function rules(): array
{
return [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'confirmed', 'min:8'],
];
}
snake_case for variables and kebab-case for classes:
<x-input type="text" name="user_name" :value="old('user_name', $user->name)" />
Testing Patterns:
"Write a feature test for
UserController@storeUserwith happy path and error cases." Output:
public function test_store_user_creates_user()
{
$userData = UserFactory::new()->raw();
$response = $this->post('/users', $userData);
$response->assertCreated();
$this->assertDatabaseHas('users', $userData);
}
.ai/guidelines/boost-spatie-guidelines/config.php (e.g., adjust max_line_length or disallowed_functions).php-cs-fixer:
Run php-cs-fixer fix to align existing code with Spatie’s standards after Boost generates snippets.Over-Reliance on AI:
if-else for happy path)."Write a minimal
UserControllerforstorewith Spatie’s happy path—avoid unnecessary comments."
Type Hint Conflicts:
?string for nullable fields where string|null is preferred (PHP 8.1+).config/boost.php:
'preferred_nullable_syntax' => 'string|null', // Override default
Blade Template Quirks:
@if instead of @unless for negative conditions."Use
@unlessfor negative conditions in Blade, following Spatie’s guidelines."
Route Caching:
Route::model() or API resource grouping."Group routes under
/api/v1and useRoute::apiResourceforPost."
Guideline Overrides:
.ai/guidelines/boost-spatie-guidelines/rules.php:
return [
'disallowed_functions' => [
'strtolower', // Temporarily allow for case-insensitive checks
],
];
Boost Logs:
config/boost.php to debug why Boost ignores your prompts:
'debug' => env('BOOST_DEBUG', false),
Extending Guidelines:
SpatieGuidelines in .ai/guidelines/boost-spatie-guidelines/SpatieGuidelines.php:
public function getCustomRules(): array
{
return [
'types' => [
'App\\Models\\User' => 'UserModel',
],
];
}
Performance:
AppServiceProvider) may slow down Boost’s analysis.@boost-ignore comments:
// @boost-ignore
public function boot()
{
// Complex legacy code
}
spatie/laravel-ignition:
Use Ignition’s error pages to validate Boost-generated code against Spatie’s conventions.php artisan boost:validate (if supported) to catch guideline violations early.How can I help you explore Laravel packages today?