skillfed

Laravel Idioms

Learn Laravel's idiomatic approach to building maintainable applications through Eloquent query scopes, service-oriented architecture, and Form Request validation. Covers testing with Pest, code formatting with Pint, and static analysis via PHPStan to enforce framework best practices.

Laravel Idioms teaches framework conventions for Eloquent, services, validation, and testing.

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

150 48 MIT updated by irahardianto

Install

irahardianto/awesome-agv/laravel-idioms · repository language: JavaScript

git clone https://github.com/irahardianto/awesome-agv
cp -r awesome-agv/.agents/skills/laravel-idioms ~/.claude/skills/laravel-idioms
npx skillfed install irahardianto/awesome-agv/laravel-idioms

Frequently asked questions

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

How to write idiomatic Laravel code following framework conventions?

Laravel Idioms teaches you to embrace the framework's opinionated patterns: use Eloquent scopes for query reusability, keep controllers thin by delegating business logic to service classes, and leverage Form Request validation for clean input handling. The skill covers Laravel's conventions around naming, file structure, and architectural layers so your code feels natural to other Laravel developers and stays maintainable as your application grows.

What's the best way to prevent N+1 query problems in Laravel?

Laravel Idioms addresses the N+1 query problem through Eloquent's eager loading features. Learn to use `with()` and `load()` to fetch related data in a single query, apply query scopes to encapsulate complex conditions, and recognize when lazy loading creates performance bottlenecks. The skill teaches you to profile queries and structure your Eloquent models so you avoid unnecessary database round-trips.

How should Laravel service layer and thin controllers be structured?

Laravel Idioms demonstrates the service layer pattern: controllers handle HTTP concerns (requests, responses, routing), while services contain business logic, database interactions, and domain rules. This separation keeps controllers thin and testable, makes services reusable across multiple endpoints, and clarifies where to add new features. You'll learn when to extract logic into services and how to inject them cleanly into your controllers.

Which testing, validation, and code quality tools does Laravel Idioms cover?

Laravel Idioms includes Pest for modern, expressive testing; Form Request validation for declarative input rules; PHPStan with Larastan for static analysis that catches type errors early; and Pint for automated code formatting. Together these tools enforce Laravel best practices, catch bugs before production, and ensure your codebase meets quality standards without manual review overhead.

What are Laravel Eloquent scopes and how do they apply DRY principles?

Laravel Idioms teaches Eloquent scopes as reusable query filters that live on your models. Instead of repeating `where()` clauses across your application, define a scope once—like `scopeActive()` or `scopeRecent()`—and chain it wherever needed. This DRY approach keeps query logic centralized, makes it easy to update filtering rules, and makes your code more readable by expressing intent rather than raw SQL conditions.

How do Laravel accessors and mutators improve code maintainability?

Laravel Idioms covers accessors and mutators as Eloquent features that transform attribute values on retrieval and storage. Use them to format dates, encrypt sensitive data, or compute derived properties without cluttering your controller or service logic. This keeps data transformation rules colocated with your model, makes attributes behave consistently across your application, and reduces the chance of formatting bugs.

SKILL.md

rendered from the published skill — quoted content, verbatim

Laravel Idioms and Patterns

Laravel rewards convention, Eloquent, and expressive syntax. Idiomatic Laravel = DRY, service-oriented, well-tested.

> Scope: Laravel-specific patterns. For PHP: @.agents/skills/php-idioms/SKILL.md.

Eloquent

  1. Scopes for reusable queries: php class Task extends Model { public function scopeActive(Builder $query): Builder { return $query->where('status', 'active'); } } // Usage: Task::active()->paginate(25);

  2. Eager loading to avoid N+1: Task::with('user', 'tags')->get().

  3. Accessors/Mutators with Attribute cast (Laravel 9+).

Service Layer

  1. Services for business logic — controllers stay thin: ```php class TaskService { public function __construct( private readonly TaskRepository $repository, ) {}

    public function create(CreateTaskRequest $request): Task { ... } } ```

Validation

  1. Form Requests for validation — never validate in controllers: ```php class CreateTaskRequest extends FormRequest { public function

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

Read as markdown · JSON record · Browse the source repository

File tree — 1 file
.agents/skills/laravel-idioms/SKILL.md

Related skills

Tags

eloquent-orm service-layer code-quality testing-framework query-optimization design-patterns static-analysis validation-rules test-factories code-conventions