laravel-best-practices

Applies Laravel PHP best practices when writing, reviewing, or refactoring backend code.

Updated Aug 24, 2026
One-click install
npx skills add https://github.com/Mantis-Technology/mantis-laravel --skill laravel-best-practices-mantis-technology
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: laravel-best-practices
Source: https://github.com/Mantis-Technology/mantis-laravel/tree/main/.agents/skills/laravel-best-practices
Command: npx skills add https://github.com/Mantis-Technology/mantis-laravel --skill laravel-best-practices-mantis-technology

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Laravel offers multiple valid ways to solve the same problem, which leads to inconsistent codebases, N+1 query bugs, security gaps, and performance regressions. This Skill provides an indexed rule set covering the full Laravel stack so code is written and reviewed against consistent, proven conventions. ## Core Features & Use Cases - Indexed Rule Library: Twenty rule files covering Eloquent, migrations, validation, routing, security, caching, queues, scheduling, testing, Blade, and architecture, each with incorrect/correct code examples. - Performance & Security Guidance: Concrete patterns for eliminating N+1 queries, adding indexes, enforcing authorization, preventing mass assignment, and validating file uploads. - Consistency-First Reviews: Instructs checking existing codebase patterns before applying rules, so refactors match project conventions instead of introducing competing styles. - Use Case: When reviewing a pull request that adds a new controller with Eloquent queries, map the changes to the routing, db-performance, and validation rule files and verify the code against each pattern. ## Quick Start Ask the AI to review your Laravel controller, model, or migration against the Laravel best practices rules and fix any violations it finds.

Frequently Asked Questions about laravel-best-practices

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

FAQPage Schema
How do I fix N+1 query problems in Laravel?▼

Use eager loading with the with() method to load relationships upfront instead of lazy loading inside loops. You can also enable Model::preventLazyLoading() in development to throw exceptions whenever a relationship is accessed without being eager-loaded.

How to validate form input in Laravel controllers?▼

Extract validation into dedicated Form Request classes and type-hint them in controller methods, which triggers validation automatically. Always use $request->validated() for mass assignment instead of $request->all() to only accept validated fields.

Should I use whereHas or whereIn for Laravel relationship queries?▼

Prefer whereIn with a select('id') subquery over whereHas for filtering by related models. whereHas emits a correlated EXISTS subquery that re-executes per row, while whereIn lets the database use an index lookup.

When should I use cursor() vs chunk() in Laravel?▼

Use cursor() for read-only iteration over large datasets since it loads one record at a time, but note it cannot eager-load relationships. Use chunk() or chunkById() when modifying records during iteration, with chunkById() being safe against row shifts.

Why is my Laravel queued job running twice?▼

Duplicate execution happens when the queue's retry_after value is shorter than the job's timeout, causing the worker to re-dispatch a still-running job. Set retry_after greater than the maximum job timeout and implement ShouldBeUnique to prevent duplicate processing.