laravel-best-practices

Review and refactor Laravel PHP code for best-practice patterns.

2|Updated Mar 3, 2025
One-click install
npx skills add https://github.com/dspangenberg/opsc --skill laravel-best-practices-dspangenberg
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: laravel-best-practices
Source: https://github.com/dspangenberg/opsc/tree/main/.junie/skills/laravel-best-practices
Command: npx skills add https://github.com/dspangenberg/opsc --skill laravel-best-practices-dspangenberg

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps teams write, review, and refactor Laravel code with consistent, production-ready practices, reducing bugs, N+1 queries, security gaps, and architectural drift.

Core Features & Use Cases

  • Database and Eloquent guidance: Improves query performance, relationship loading, indexing, and reusable model patterns.
  • Security and validation guardrails: Reinforces authorization, mass assignment safety, input validation, file upload checks, and secret handling.
  • Architecture and workflow support: Guides routing, controllers, jobs, caching, scheduling, testing, error handling, and Blade conventions.
  • Use case: Refactor a Laravel controller, migration, or query-heavy feature to match the codebase’s existing style while applying best-practice defaults where patterns are missing.

Quick Start

Review the Laravel code I provide and refactor it to follow the most relevant best practices for performance, security, validation, and maintainability.

Frequently Asked Questions about laravel-best-practices

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

FAQPage Schema
How do I refactor a Laravel controller to fix N+1 query problems?

To fix Laravel N+1 query problems during a refactor, apply Eloquent eager loading patterns to relationship queries, ensuring models load associated data efficiently and reducing performance regressions in the controller logic.

What is the best way to add validation and authorization in Laravel requests?

The best way to add validation and authorization in Laravel is by enforcing mass assignment safety, strict input validation, and dedicated request authorization guardrails within your backend application code to reduce security risks.

How do I review Laravel code for security gaps and mass assignment risks?

Review Laravel code for security gaps by checking for proper file upload validation, secret handling, mass assignment protection, and consistent authorization enforcement across controllers and models to prevent vulnerabilities.

Does this approach apply to Laravel queue configuration and job scheduling?

Yes, this approach applies to Laravel queue configuration and job scheduling by providing architectural guidance for jobs, scheduling, caching, and error handling to ensure consistent workflow patterns within your application.

Why does my Laravel migration architecture drift from existing codebase style?

Laravel migration architecture drifts when style consistency is missing, but applying best-practice patterns during refactoring aligns database design, routing, and testing conventions with the existing codebase to prevent structural bugs.