Laravel Idioms and Patterns

Enforce Eloquent, service-layer, validation, and testing conventions in Laravel PHP applications.

150|48|Updated Jan 24, 2026
One-click install
npx skills add https://github.com/irahardianto/awesome-agv --skill laravel-idioms-and-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Laravel Idioms and Patterns
Source: https://github.com/irahardianto/awesome-agv/tree/main/.agents/skills/laravel-idioms
Command: npx skills add https://github.com/irahardianto/awesome-agv --skill laravel-idioms-and-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It prevents non-idiomatic, tightly coupled Laravel code by guiding agents toward conventions and patterns that improve maintainability, testability, and performance.

Core Features & Use Cases

  • Eloquent query patterns: Encourages scopes for reusable queries and eager loading to avoid N+1 queries in API-heavy apps.
  • Service layer separation: Moves business logic out of controllers to keep endpoints thin and easier to test and evolve.
  • Validation and testing conventions: Uses Form Requests for validation and promotes Pest/PHPUnit patterns with factories and isolated database tests.
  • Formatting and static analysis workflow: Recommends Laravel Pint, PHPStan/Larastan, and composer audit to keep code consistent and safer over time.

Quick Start

Ask your AI agent to refactor your Laravel endpoint so it uses a Form Request for validation, a service layer for business logic, and Eloquent scopes with eager loading, then add a Pest test with factories that asserts the created record exists in the database.

Frequently Asked Questions about Laravel Idioms and Patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent N+1 queries in Laravel Eloquent when building APIs?

To prevent N+1 queries in Laravel Eloquent, use eager loading with the `with()` method to fetch relationships upfront. This Skill enforces eager loading conventions and reusable query scopes to optimize API performance and maintainability.

How do I separate business logic from controllers in Laravel?

To separate business logic from controllers in Laravel, move it into a dedicated service layer. This Skill guides agents to create thin controllers by delegating endpoint operations to service classes, improving testability and architectural evolution.

What's the best way to handle validation in Laravel REST API development?

The best way to handle validation in Laravel is using Form Requests. This Skill enforces Form Request conventions to encapsulate validation rules, keeping controllers clean and ensuring data integrity for REST/API development.

How do I write repeatable database tests for Laravel using Pest?

To write repeatable database tests in Laravel using Pest, utilize model factories and assert created records exist in an isolated database. This Skill promotes Pest and PHPUnit patterns with factories to ensure reliable and isolated testing workflows.

Does this approach work with static analysis tools like PHPStan?

Yes, this approach integrates with static analysis by recommending Larastan and PHPStan. This Skill guides agents to produce code that passes static analysis checks, ensuring safer and more consistent Laravel applications over time.