These guidelines are all about code consistency. Want to learn more about maintainable code that your future self and colleagues will understand?
Check out our online course at writing-readable-php.com.
Using our guidelines with AI
Introduction
Claude Code is Anthropic's official CLI tool that helps developers write better code by providing AI-powered assistance directly in your terminal. It can understand and apply coding standards, making it perfect for maintaining consistency across your Laravel projects.
We've created AI-optimized guidelines specifically formatted for Claude Code and similar agents to ensure it generates code that follows Spatie's Laravel & PHP standards.
Our AI-optimized guidelines cover:
- Core Laravel principles - Follow documented Laravel conventions first
- PHP standards - PSR compliance, type declarations, nullable syntax
- Class structure - Typed properties, constructor promotion, traits
- Control flow - Early returns, avoiding else statements, happy path patterns
- Laravel conventions - Routes, controllers, configuration, artisan commands
- Naming conventions - Complete reference for classes, methods, files, and URLs
- Code quality reminders - Essential principles for maintainable code
You can view the file with AI-optimized guidelines here.
Global Integration using Claude Code
Add the guidelines to your global Claude Code configuration so they're available across all projects:
# Make sure the Claude configuration file exists mkdir -p ~/.claude && touch ~/.claude/CLAUDE.md # Download our guidelines curl -o ~/.claude/laravel-php-guidelines.md https://spatie.be/laravel-php-ai-guidelines.md # Tell Claude to read the guidelines file echo -e '\n## Coding Standards\nWhen working with Laravel/PHP projects, first read the coding guidelines at @~/.claude/laravel-php-guidelines.md' >> ~/.claude/CLAUDE.md
Project-Specific Integration using Claude Code
For individual Laravel projects, download the guidelines to your project root:
# Make sure the Claude configuration file exists touch CLAUDE.md # Download our guidelines curl -o laravel-php-guidelines.md https://spatie.be/laravel-php-ai-guidelines.md # Tell Claude to read the guidelines file echo -e '\n## Coding Standards\nWhen working on this Laravel/PHP project, first read the coding guidelines at @laravel-php-guidelines.md' >> CLAUDE.md
Optionally, you can create a Composer script to keep guidelines updated:
{ "scripts": { "update-guidelines": "curl -o docs/laravel-php-guidelines.md https://spatie.be/laravel-php-ai-guidelines.md" } }
AI docs for Spatie packages
The Context7 MCP project contains docs for various Spatie packages.