laravel-patterns
What it does
This guide teaches how to organize and structure projects built with Laravel, a web programming framework. It shows how to make code cleaner, easier to understand, and maintainable, using best practices.
When to use it
- βWhen starting a new Laravel project.
- βWhen reviewing or improving an existing Laravel project.
- βWhen working with routes, data models (Eloquent), or business logic.
Skill link
https://github.com/affaan-m/ECC/blob/main/pi/core/skills/laravel-patterns/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agentβs skills folder.
Example of what to ask your AI
βHow can I better organize my code in a Laravel project to make it more scalable?β
5 new skills a week. 1 minute to read.
How it works
It suggests separating responsibilities into different code parts, like controllers, services, and models. It also guides on using Laravel features like queues, events, and caching to optimize performance.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
Laravel Development Patterns
Production-grade Laravel architecture patterns for scalable, maintainable applications.
When to Use
- Building Laravel web applications or APIs
- Structuring controllers, services, and domain logic
- Working with Eloquent models and relationships
- Designing APIs with resources and pagination
- Adding queues, events, caching, and background jobs
How It Works
- Structure the app around clear boundaries (controllers -> services/actions -> models).
- Use explicit bindings and scoped bindings to keep routing predictable; still enforce authorization for access control.
- Favor typed models, casts, and scopes to keep domain logic consistent.
- Keep IO-heavy work in queues and cache expensive reads.
- Centralize config in
config/*and keep environments explicit.
Examples
Project Structure
Use a conventional Laravel layout with clear layer boundaries (HTTP, services/actions, models).
Recommended Layout
app/
βββ Actions/ # Single-purpose use cases
βββ Console/
βββ Events/
βββ Exceptions/
βββ Http/
β βββ Controllers/
β βββ Middleware/
β βββ Requests/ # Form request validation
β βββ Resources/ # API resources
βββ Jobs/
βββ Models/
βββ Policies/
βββ Providers/
βββ Services/ # Coordinating domain services
βββ Support/
config/
database/
βββ factories/
βββ migrations/
βββ seeders/
resources/
βββ views/
βββ lang/
routes/
βββ api.php
βββ web.php
βββ console.php
Controllers -> Services -> Actions
Keep controllers thin. Put orchestration in services and single-purpose logic in actions.
final class CreateOrderAction
{
public function __construct(private OrderRepository $orders) {}
public function handle(CreateOrderData $data): Order
{
return $this->orders->create($data);
}
}
final class OrdersController extends Controller
{
public function __construct(private CreateOrderAction $createOrder) {}
public function store(StoreOrderRequest $request): JsonResponse
{
$order = $this->createOrder->handle($request->toDto());
return response()->json([
'success' => true,
'data' => OrderResource::make($order),
'error' => null,
'meta' => null,
], 201);
}
}
Routing and Controllers
Prefer route-model binding and resource controllers for clarity.
use Illuminate\Support\Facades\Route;
Route::middleware('auth:sanctum')->group(function () {
Route::apiResource('projects', ProjectController::class);
});
Route Model Binding (Scoped)
Use scoped bindings to prevent cross-tenant access.
Route::scopeBindings()->group(function () {
Route::get('/accounts/{account}/projects/{project}', [ProjectController::class, 'show']);
});
Nested Routes and Binding Names
- Keep prefixes and paths consistent to avoid double nesting (e.g.,
conversationvsconversations). - Use a single parameter name that matches the bound model (e.g.,
{conversation}forConversation). - Prefer scoped bindings when nesting to enforce parent-child relationships.
use App\Http\Controllers\Api\ConversationController;
use App\Http\Controllers\Api\MessageController;
use Illuminate\Support\Facades\Route;
Route::middleware('auth:sanctum')->prefix('conversations')->group(function () {
Route::post('/', [ConversationController::class, 'store'])->name('conversations.store');
Route::scopeBindings()->group(function () {
Route::get('/{conversation}', [ConversationController::class, 'show'])
->name('conversations.show');
Route::post('/{conversation}/messages', [MessageController::class, 'store'])
->name('conversation-messages.store');
Route::get('/{conversation}/messages/{message}', [MessageController::class, 'show'])
->name('conversation-messages.show');
});
});
If you want a parameter to resolve to a different model class, define explicit binding. For custom binding logic, use Route::bind() or implement resolveRouteBinding() on the model.
use App\Models\AiConversation;
use Illuminate\Support\Facades\Route;
Route::model('conversation', AiConversation::class);
Service Container Bindings
Bind interfaces to implementations in a service provider for clear dependency wiring.
use App\Repositories\EloquentOrderRepository;
use App\Repositories\OrderRepository;
use Illuminate\Support\ServiceProvider;
β¦
FAQ
What are 'architecture patterns'?
They are tested and approved ways of organizing a program's code so it's easier to understand, maintain, and grow.
What is Eloquent ORM?
It's a Laravel tool that makes interacting with the database easier, allowing you to use PHP code to represent and manipulate your data, instead of writing SQL directly.
Why use 'layers' in code?
Separating code into layers (like interface, business logic, and data access) helps organize tasks and makes it easier to modify one part without affecting others.
Details
Original description by the author
Laravel architecture patterns, routing/controllers, Eloquent ORM, service layers, queues, events, caching, and API resources for production apps. Use when building or reviewing Laravel apps β controllers, Eloquent, service layers, queues, or API resources.
repo: affaan-m/ECC
Popularity
- GitHub stars
- 280k
- Ranking position
- #199
- License
- MIT
- Updated
- 10/15/2026
Comments
- β¦
More skills from this repository
accessibility
280kHelps your agent create interfaces that everyone can use. Ensures websites and apps work well for people with disabilities, like those who are blind or have reduced mobility.
agent-architecture-audit
280kMakes your agent check if everything is working correctly. It finds and fixes problems in AI systems, ensuring they perform as expected.
agent-eval
280kHelps your agent compare different AI coding tools. It measures which one is faster, cheaper, and more reliable for specific tasks.
agent-harness-construction
280kMakes your agent better understand how to perform tasks. It optimizes the tools and instructions the agent uses to increase its chances of success.
Similar skills
diffs
394kLets your agent produce a real, shareable diff of edits as a viewer link or image file, instead of a hand-written summary.
coding-agent
394kHelps your agent hand a larger coding job to Codex, Claude Code, or OpenCode as a background worker, then check on its progress.
gh-issues
394kHelps your agent find GitHub issues, pick the ones to work on, and open pull requests with fixes, including follow-up on review comments.