---
name: laravel-code-quality
description: Use when writing, reviewing or cleaning up Laravel PHP for quality and safety rather than layout — formatting with Pint, one-line method signatures, named arguments, the few-comments rule and when PHPDoc is allowed, naming and types, readable conditionals (guard clauses, named conditions, elseif, match), private methods over single-use classes; security (fail-closed authorization, routes inside auth groups, file-route permissions, row-level visibility, Form Request validation, one-value-or-list fields, mass assignment, bound raw SQL, XSS, secrets and env(), throttle keys, random_int, signed public links); sensitive operations such as refunds, payouts, data exports and access grants (duplicate-submit protection, once-only execution, maker-checker approvals, self-approval, overrides, step-up auth, append-only audit logs, masking, bounded output); tests that guard all of this; the numbered anti-pattern catalogue; the code review report format. Also triggers on "review this diff", "code review", "clean this up", "is this secure", "anti-pattern", "double submit", "approval flow", "audit log", "مراجعة الكود", "جودة الكود", "تنظيف الكود", "التعليقات", "ثغرة", "أمان", "موافقات".
metadata:
  summary: "Laravel code style, security, sensitive operations and code review."
  tags: laravel, php, security, code-review, clean-code
title: laravel-code-quality
canonical_url: https://skilld.dev/gh/haythamasalama/skills/laravel-code-quality
last_updated: 2026-11-03T23:16:06.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [references/anti-patterns.md](https://skilld.dev/api/skills-raw/haythamasalama/skills/laravel-code-quality/references/anti-patterns.md), [references/code-style-and-comments.md](https://skilld.dev/api/skills-raw/haythamasalama/skills/laravel-code-quality/references/code-style-and-comments.md), [references/conditionals.md](https://skilld.dev/api/skills-raw/haythamasalama/skills/laravel-code-quality/references/conditionals.md), [references/review-output.md](https://skilld.dev/api/skills-raw/haythamasalama/skills/laravel-code-quality/references/review-output.md), [references/security.md](https://skilld.dev/api/skills-raw/haythamasalama/skills/laravel-code-quality/references/security.md), [references/sensitive-operations.md](https://skilld.dev/api/skills-raw/haythamasalama/skills/laravel-code-quality/references/sensitive-operations.md), [references/testing.md](https://skilld.dev/api/skills-raw/haythamasalama/skills/laravel-code-quality/references/testing.md).
>
> If the user asked to install this Skill, run `npx skilld install haythamasalama/skills/laravel-code-quality`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/laravel-code-quality`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/haythamasalama/skills/laravel-code-quality) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/laravel-code-quality`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/laravel-code-quality --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/laravel-code-quality --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Laravel code quality

**Read when:** reviewing a diff, finishing a change, or writing code that touches permissions, input,
raw SQL, secrets, audit trails, approvals or anything that must run only once.
**Owns:** style and comments, conditionals, security rules, sensitive-operation patterns, testing rules
for those paths, the anti-pattern catalogue (stable numbers), the review report format and severity.

Written for PHP 8.3+, Laravel 12 and Pest 4 (checked 2026-11-03). Match the codebase first: these are
defaults for new code, not a reason to rewrite working code in an unrelated change.

## TL;DR

- **Pint owns formatting**: `vendor/bin/pint --dirty` on changed files. Never hand-align.
- **One-line method signatures.** Only DTO constructors list one property per line.
- **Named arguments** when a call passes a bare literal or two values that could be swapped unnoticed.
- **Write few comments.** Default to none; keep a 1–2 line WHY a reader would get wrong without it.
- **Readable conditionals:** guard clauses first, named conditions, one `elseif` chain for an exclusive
  choice, `match` or a map when branches only pick values.
- **Fail closed.** Deny by default, check on the server every time, record denials. An empty scope
  narrows to nothing, never to everything.
- **Every route inside its auth group;** a file or export route checks the linking page's permission.
- **Bind every SQL value.** Identifiers come from an allowlist. `{!! !!}` only through a sanitizer.
- **Secrets never leave**: not in responses, logs, DTOs, errors or the repository. `config()`, not `env()`.
- **Once-only work claims the row atomically;** a form that must not run twice carries a server-issued key.
- **Nobody approves their own request;** nothing is written while a change waits for approval.
- **Audit logs are append-only** and record denials and overrides, without secrets or raw personal data.
- **Never skip or delete a failing test**; never point a test run at a working database.

## Before you call a change done

1. `vendor/bin/pint --dirty`.
2. Run the affected tests (`php artisan test --compact --filter=…`), including a failure path.
3. Read the diff against the [anti-pattern catalogue](https://skilld.dev/api/skills-raw/haythamasalama/skills/laravel-code-quality/references/anti-patterns.md).
4. Run the [comment check](https://skilld.dev/api/skills-raw/haythamasalama/skills/laravel-code-quality/references/code-style-and-comments.md#the-check-before-calling-a-change-done).
5. Security pass for anything touching routes, input, SQL, output, secrets or permissions.

## Where each topic lives

| I'm working on… | Read |
|---|---|
| Formatting, signatures, named arguments, comments, PHPDoc, naming, types, `readonly`, morph types | [code-style-and-comments.md](https://skilld.dev/api/skills-raw/haythamasalama/skills/laravel-code-quality/references/code-style-and-comments.md) |
| An `if`, `elseif`, `match`, ternary or compound condition | [conditionals.md](https://skilld.dev/api/skills-raw/haythamasalama/skills/laravel-code-quality/references/conditionals.md) |
| Routes, permissions, row visibility, validation, mass assignment, raw SQL, XSS, secrets, throttles, public links | [security.md](https://skilld.dev/api/skills-raw/haythamasalama/skills/laravel-code-quality/references/security.md) |
| Refunds, payouts, exports, access grants: duplicate submits, once-only, approvals, overrides, step-up, audit logs, masking | [sensitive-operations.md](https://skilld.dev/api/skills-raw/haythamasalama/skills/laravel-code-quality/references/sensitive-operations.md) |
| The test database, what to test at which layer, fakes, failure paths | [testing.md](https://skilld.dev/api/skills-raw/haythamasalama/skills/laravel-code-quality/references/testing.md) |
| Checking a diff against known mistakes (numbered) | [anti-patterns.md](https://skilld.dev/api/skills-raw/haythamasalama/skills/laravel-code-quality/references/anti-patterns.md) |
| Writing up a review, and what each severity means | [review-output.md](https://skilld.dev/api/skills-raw/haythamasalama/skills/laravel-code-quality/references/review-output.md) |

Cite findings by anti-pattern number (`#40`) and `file:line`; numbers never change. Severity
(🔴 / 🟡 / 🟢) is defined once, in [review-output.md](https://skilld.dev/api/skills-raw/haythamasalama/skills/laravel-code-quality/references/review-output.md#severity).

## Decided rules that look odd

These go against generic Laravel advice on purpose. Do not "fix" them in review.

| Rule | Why |
|---|---|
| Few comments, no docblocks that restate signatures | typed signatures say more; restating comments rot |
| One-line signatures, even long ones | every method scans the same; a signature diff is one line |
| DTO (a `readonly` class that carries data between layers, named `*Data`) properties in `snake_case` | keys match columns and validated input; no mapping layer |
| Static single-operation classes (`final class IssueInvoice { public static function handle() }`) resolve their dependencies with `app()` | a static method cannot take constructor injection; one pattern end to end |
| Methods that read from a module may return Eloquent models instead of read DTOs | a later refactor; never block a change on it (#12) |
| No speculative indexes; never custom-name indexes or constraints | write cost; custom names drift between environments |
| A private method rather than a new single-use class | files earn their place through reuse |
| `$guarded = []` tolerated on existing models whose writes all pass through a DTO | the DTO lists the columns; new user-input models still use `$fillable` |
