anantbhandarkar/make-it-right/mir-backend-php-laravel

Claude Code and agent skill by anantbhandarkar/make-it-right

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Make It Right (Laravel module). Laravel 13 / 12 + Eloquent ORM + MySQL/PostgreSQL + Redis + Laravel Queues + Octane + the Laravel AI SDK — mechanical reliability augmentation. Use alongside mir-backend and mir-backend-php when the target stack is Laravel; it carries the footguns the framework-agnostic tiers deliberately omit: Eloquent N+1 and automatic eager loading, mass assignment via $fillable/$guarded and the forceFill bypass, queued vs. inline work with the Laravel 13 job attributes, DB::transaction() boundaries and afterCommit semantics, migrations that are NOT transactional on MySQL, Octane container/request/config injection bleed, and prompt injection plus tool authorization in the Laravel AI SDK. TRIGGER only when the PHP backend stack is Laravel — building, reviewing, or debugging a Laravel controller, Eloquent model, Job, migration, policy, middleware, or AI agent/tool. Always loads TOGETHER WITH mir-backend (the gates) and mir-backend-php (Zend Engine runtime concerns: shared-nothing lifecycle, FPM worker model, worker-runtime state bleed, opcache/JIT, php.ini security, Composer supply chain); this module only adds Laravel/Eloquent library mechanics. SKIP for Symfony/Doctrine/Messenger/API Platform work (that is mir-backend-php-symfony), for WordPress, Slim, or any non-Laravel PHP stack (each gets its own mir-backend-php-<framework> module), and for non-PHP runtimes.

Install

npx vskill@latest install anantbhandarkar/make-it-right/mir-backend-php-laravel

SKILL.md

The same SKILL.md was published earlier as anantbhandarkar/make-it-right/mir-backend-php-laravel.

/mir-backend-php-laravel · Make It Right (Laravel)

Bottom tier of the chain: mir-backend (generic gates) → mir-backend-php (Zend Engine runtime model) → this (Laravel/Eloquent library mechanics). Run the gates first; load the PHP runtime tier for the lifecycle/process model; reach for this at Gate 5 (design mechanics), Gate 6 (implementation), and Gate 7 review. Runtime-level concerns (shared-nothing lifecycle, FPM sizing, worker-runtime state bleed, opcache/JIT, php.ini hardening, Composer supply chain) live in `mir-backend-php` — not here.

Versions, verified 13 August 2026:

ReleaseDatePHPBug fixes untilSecurity until
Laravel 1317 Mar 20268.3 – 8.5Q3 202717 Mar 2028
Laravel 1224 Feb 20258.2 – 8.513 Aug 2026 — just lapsed24 Feb 2027
Laravel 1112 Mar 20248.2 – 8.4endedended 12 Mar 2026
Laravel 1014 Feb 20238.1 – 8.3endedended

There is no LTS release. Laravel has not shipped an LTS since version 6. Every major gets 18 months of bug fixes and 2 years of security fixes. If a project is on Laravel 11 or older it is receiving nothing — that is a Gate 5 risk-register entry, not a "later" item.

Stack assumed: Laravel 13 (or 12) · Eloquent ORM · MySQL or PostgreSQL · Redis · Laravel Queues (Horizon or plain queue:work). Note that some Laravel 13.3+ patch versions pull Symfony 8 components that require PHP 8.4, so a project pinned to PHP 8.3 may not be able to take the newest 13.x patch. If the project uses a different queue driver or a raw PDO layer, note the divergence before applying these.

The Laravel footguns AI walks into most

1. Eloquent N+1 — the silent query multiplier

Eloquent lazy-loads relationships on first access. Inside a loop over a collection, accessing $order->items for each order fires a separate SELECT per iteration — N orders produce N+1 queries.

  • Fix: eager-load with with() in the initial query. Turn on Model::preventLazyLoading() outside production — it throws LazyLoadingViolationException the moment a lazy load is attempted, so N+1 fails in CI instead of in prod.
  • Model::shouldBeStrict() is the one-liner: it calls preventLazyLoading(), preventSilentlyDiscardingAttributes(), and preventAccessingMissingAttributes(). The last two are correctness checks and are safe to leave on everywhere; the lazy-loading one is usually scoped to non-production.
php
// WRONG — fires 1 + N queries (1 for orders, N for items)
$orders = Order::all();
foreach ($orders as $order) {
echo $order->items->count(); // lazy load per iteration
}
// RIGHT — 2 queries total
$orders = Order::with('items')->get();
// Dev/CI guard — AppServiceProvider::boot()
Model::shouldBeStrict(! app()->isProduction());
Model::preventSilentlyDiscardingAttributes(); // keep this one on in prod too

Nested relationships: with('items.product'). Aggregate counts without hydrating the relation: withCount().

Automatic eager loading (added in Laravel 12.0.8, still labelled beta): Model::automaticallyEagerLoadRelationships() makes Eloquent batch-load a relationship the first time any model in a loaded collection touches it. It removes most manual with() calls, and it no longer conflicts with preventLazyLoading — accessing a relation under automatic eager loading does not raise the violation. Two cautions: it only helps when the models are in one loaded collection (a relation accessed on a single model still fires its own query), and turning it on globally changes query shapes across the whole app, so verify the query log before shipping it to a hot path.

2. Mass assignment — $fillable / $guarded, and the bypasses

Model::create($request->all()) or $model->fill($request->all()) passes the entire HTTP payload to Eloquent.

Get the default right, because AI states it wrong in both directions. The base Illuminate\Database\Eloquent\Model ships $fillable = [] and $guarded = ['*']. That combination is "totally guarded": fill() throws MassAssignmentException rather than writing anything. Laravel is closed by default. The dangerous states are all things a developer opts into:

PatternEffect
protected $guarded = [];every column is mass-assignable — this is the actual overposting hole, and it is common because tutorials recommend it
Model::unguard() in a service providersame, globally, for every model
$model->forceFill($request->all()) / forceCreate()bypasses $fillable and $guarded entirely, including id
$fillable that includes role, is_admin, tenant_id, user_id, stripe_customer_idthe allow-list itself is the hole

Non-fillable attributes are silently discarded by default — no error, no log, the field just does not save. That hides bugs. Model::preventSilentlyDiscardingAttributes() turns it into an exception.

php
// WRONG — open to overposting; any field in the body is written
class User extends Model {
protected $guarded = []; // nothing guarded
}
User::create($request->all()); // client sends is_admin=1 → it sticks
// RIGHT — explicit allow-list + Form Request validation
class User extends Model {
protected $fillable = ['name', 'email', 'password'];
}
class StoreUserRequest extends FormRequest {
public function rules(): array {
return [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'email', 'unique:users'],
'password' => ['required', 'min:12', 'confirmed'],
];
}
}
// Controller — only validated fields reach the model
User::create($request->validated());

$request->validated() returns only fields that had rules. $request->all() returns everything the client sent. Never pass all() to create, fill, update, or forceFill.

3. Queue jobs for heavy / durable work — not inline in the request

Laravel's HTTP workers are budgeted for fast responses. Heavy computation (PDF generation, bulk email, image processing, third-party API calls with retries) must not run synchronously in a controller action. If the process dies or the request times out, the work is lost.

  • Fix: dispatch a Job. Jobs are durable (Redis/DB queue), retryable, and monitorable (Horizon). Make handlers idempotent — a job can be retried after partial success; re-running must not double-charge, double-email, or double-insert.
  • Laravel 13 adds attribute equivalents for the job control properties: #[Tries], #[Backoff], #[Timeout], #[FailOnTimeout]. Use whichever form the codebase already uses; do not mix.
  • Queue::route(ProcessPodcast::class, connection: 'redis', queue: 'podcasts') (Laravel 13) centralises which queue a job class lands on, instead of scattering onQueue() at every dispatch site.
  • ShouldBeUnique (with uniqueId() and uniqueFor()) prevents a duplicate job being queued. It is a de-duplication convenience backed by a cache lock — it is not an idempotency guarantee. Still write the handler to be safe on redelivery.
php
// WRONG — slow/failable work in the request lifecycle
public function store(Request $request): JsonResponse {
$report = $this->reportService->generate($request->validated()); // 30 s of CPU
Mail::to($request->user())->send(new ReportReady($report));
return response()->json(['status' => 'done']);
}
// RIGHT — dispatch, respond immediately, let the worker handle it
public function store(Request $request): JsonResponse {
GenerateReport::dispatch($request->validated(), $request->user()->id)
->onQueue('reports');
return response()->json(['status' => 'queued'], 202);
}
class GenerateReport implements ShouldQueue {
public int $tries = 3;
public array $backoff = [30, 60, 120];
public function handle(ReportService $service): void {
// Idempotent: the key is derived from the business event, not from dispatch time
if (Report::where('key', $this->key)->exists()) { return; }
$service->generate($this->payload, $this->userId);
}
}

Worker restarts are part of this: queue:restart after every deploy, and ext-pcntl must be present or SIGTERM kills jobs mid-flight (see mir-backend-php).

4. DB::transaction() — boundaries, deadlock retries, and afterCommit

DB::transaction() wraps a closure in BEGIN/COMMIT/ROLLBACK. AI gets three things wrong:

Wrong: firing irreversible side effects (email, HTTP call, charge) inside the transaction. If the commit succeeds but the outer code throws, or you roll back for another reason, the email is already sent.

Wrong: assuming deadlock retries happen. The $attempts parameter defaults to 1 — no retry. Raise it on write-heavy paths: DB::transaction(fn() => ..., attempts: 3). Retries re-run the whole closure, so the closure must be safe to run twice.

Wrong: model events (created, updated) that dispatch jobs or send notifications. The event fires on save(), inside the transaction. The transaction can still roll back, and the job then runs against data that was never committed. It can also run before commit and read stale rows.

php
// WRONG — email fires inside the transaction; rollback cannot un-send it
DB::transaction(function () use ($order, $payment) {
$order->markPaid($payment);
Mail::to($order->user)->send(new PaymentConfirmation($order)); // wrong place
});
// RIGHT — side effects after commit
DB::transaction(function () use ($order, $payment) {
$order->markPaid($payment);
SendPaymentConfirmation::dispatch($order)->afterCommit(); // queued only on commit
}, attempts: 3);

->afterCommit() on a dispatch, $afterCommit = true on the Job class, or DB::afterCommit(fn () => ...) for a plain callback. For state transitions under concurrency, prefer a conditional UPDATE and check the affected-row count over read-modify-write:

php
$changed = Order::where('id', $id)->where('status', 'PENDING')
->update(['status' => 'PAID']);
if ($changed === 0) { /* someone else already transitioned it */ }
5. Octane — container, request, and config injection bleed

Under Laravel Octane (FrankenPHP, Swoole, Open Swoole, or RoadRunner) the application boots once and stays in memory. Service providers' register and boot run once, at worker boot. This is the Laravel face of the runtime-level state bleed footgun in mir-backend-php. Octane resets first-party framework state between requests; it does not know how to reset yours.

The three specific traps named in Laravel's own Octane documentation:

Injected into a singleton constructorWhat goes wrong
the container (Application $app)the service holds the container as it existed at boot — later bindings and per-request bindings are missing
the request ($app['request'])headers, input, query string, and the authenticated user are all frozen at request 1 for every subsequent request
the config repository ($app->make('config'))config changes between requests are invisible to the service

Fixes, in the order the docs recommend:

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 95 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
15
7-day trend score
14

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/anantbhandarkar/make-it-right/mir-backend-php-laravel/badge)](https://verified-skill.com/skills/anantbhandarkar/make-it-right/mir-backend-php-laravel)

Something wrong with this skill or its page? Tell us.