skillfed

laravel-best-practices

Laravel Best Practices is a comprehensive reference for building scalable Laravel 13 applications, covering 31 rules organized across architecture, Eloquent patterns, controllers, validation, security, performance, and API design. Use it when structuring applications, creating models and migrations, implementing form requests, or designing APIs. Includes essential patterns for service classes, repositories, form requests, and Eloquent models.

Laravel Best Practices provides 31 rules across architecture, Eloquent, controllers, validation, security, performance, and API design for Laravel 13 applications.

AI-generated summary based on this skill's SKILL.md

58 9 MIT updated by AsyrafHussin

Install

AsyrafHussin/agent-skills/laravel-best-practices

git clone https://github.com/AsyrafHussin/agent-skills
cp -r agent-skills/skills/laravel-best-practices ~/.claude/skills/laravel-best-practices
npx skillfed install AsyrafHussin/agent-skills/laravel-best-practices

Frequently asked questions

AI-generated answers based on this skill's SKILL.md and metadata

What are the key Laravel 13 best practices for application structure?

Laravel Best Practices recommends organizing your Laravel 13 application by separating concerns across controllers, models, services, and repositories. Follow the framework's conventions for directory structure, use feature-folder organization when appropriate, and implement dependency injection throughout. Adhere to RESTful resource controller patterns, keep business logic in service classes rather than controllers, and use form requests for validation. This architecture ensures scalability and maintainability as your application grows.

How do you prevent N+1 queries and optimize Eloquent database access?

Laravel Best Practices emphasizes using Eloquent eager loading to prevent N+1 query problems. Load relationships upfront with methods like `with()` or `load()` rather than lazy-loading them in loops. Use `select()` to fetch only needed columns, leverage query scopes for reusable filters, and profile queries with Laravel's query log. Consider pagination for large datasets and use database indexes strategically. These Eloquent optimization techniques significantly improve application performance.

What is the proper way to structure controllers, models, and services?

Laravel Best Practices advocates keeping controllers thin and focused on HTTP concerns—routing requests to appropriate services and returning responses. Models should contain only data relationships and query scopes, not business logic. Service classes encapsulate business rules and complex operations, promoting reusability and testability. Use repositories for data access abstraction when needed, and implement dependency injection to wire these components together cleanly.

How should Laravel form request validation and handling be implemented?

Laravel Best Practices recommends using FormRequest classes to centralize validation logic separate from controllers. Define rules in the `rules()` method, customize messages with `messages()`, and use the `authorize()` method for permission checks. This keeps controllers clean and makes validation reusable across multiple endpoints. Leverage Laravel's built-in validators and custom rule classes for complex validation scenarios, ensuring data integrity before processing.

What security measures protect Laravel applications from mass assignment?

Laravel Best Practices emphasizes using the `$fillable` or `$guarded` properties on Eloquent models to control which attributes can be mass-assigned. Always validate user input through form requests before creating or updating models. Implement proper authorization checks using policies and gates, sanitize user data, and use prepared statements through Eloquent to prevent SQL injection. These practices build secure, scalable Laravel applications resistant to common vulnerabilities.

How do you build scalable and maintainable Laravel API applications?

Laravel Best Practices recommends designing APIs with clear resource controllers, consistent response formatting, and proper HTTP status codes. Use API resources to transform model data, implement pagination for large datasets, and version your API endpoints when needed. Apply the same architectural principles—service classes, form requests, repositories—to API code. Leverage Laravel's built-in features like API rate limiting, CORS configuration, and token authentication to create secure, scalable APIs.

SKILL.md

rendered from the published skill — quoted content, verbatim

Laravel 13 Best Practices

Comprehensive best practices guide for Laravel 13 applications. Contains 31 rules across 7 categories for building scalable, maintainable Laravel applications.

When to Apply

Reference these guidelines when: - Creating controllers, models, and services - Writing migrations and database queries - Implementing validation and form requests - Building APIs with Laravel - Structuring Laravel applications

Rule Categories by Priority

Priority Category Impact Prefix
1 Architecture & Structure CRITICAL arch-
2 Eloquent & Database CRITICAL eloquent-
3 Controllers & Routing HIGH controller-, ctrl-
4 Validation & Requests HIGH validation-,

(truncated - see the full file via the links below)

Read as markdown · JSON record · Browse the source repository

File tree — 15 files
skills/laravel-best-practices/AGENTS.md
skills/laravel-best-practices/README.md
skills/laravel-best-practices/SKILL.md
skills/laravel-best-practices/metadata.json
skills/laravel-best-practices/rules/_sections.md
skills/laravel-best-practices/rules/_template.md
skills/laravel-best-practices/rules/arch-action-classes.md
skills/laravel-best-practices/rules/arch-dto-pattern.md
skills/laravel-best-practices/rules/arch-event-driven.md
skills/laravel-best-practices/rules/arch-feature-folders.md
skills/laravel-best-practices/rules/arch-queue-routing.md
skills/laravel-best-practices/rules/arch-repository-pattern.md
skills/laravel-best-practices/rules/arch-service-classes.md
skills/laravel-best-practices/rules/arch-value-objects.md
skills/laravel-best-practices/rules/controller-api-resources.md

Related skills

Tags

code-organization database-optimization api-development security-patterns performance-tuning architectural-design validation-rules eloquent-orm scalability-guide php-framework