[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7FF5W1GHH85675C9227SVPZ":3,"skill-same:01M7FF5W1GHH85675C9227SVPZ":77},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":37,"commitSha":38,"skillDirectory":39,"forksCount":40,"repositoryHtmlUrl":41,"repositoryHomepageUrl":6,"ownerHtmlUrl":42,"ownerBlogUrl":6,"ownerDescription":43,"updatedAt":44,"install":45,"resources":58},"01M7FF5W1GHH85675C9227SVPZ","laravel",null,"Use when building or extending a Laravel 11\u002F12 app — Eloquent models, migrations and relationships, routing with controllers and Form Requests, queues and background jobs, framework-native security (validation, mass-assignment, policies, signed URLs, rate limiting), and Pest\u002FPHPUnit feature tests. NOT pure PHP language or toolchain work (that is `php`).","lza6\u002FArmor-piercing-system-prompts","lza6","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F128880206?v=4","01M7EB3K7WPX5T28EJ2NVHE6EG","Chinese-tingfeng","01M7EB3K97E1KQ16QWKJMFNGX8",11,"MIT","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Flaravel\u002FSKILL.md",[],[],"2026-11-16 10:05:34",false,"---\nname: laravel\ndescription: \"Use when building or extending a Laravel 11\u002F12 app — Eloquent models, migrations and relationships, routing with controllers and Form Requests, queues and background jobs, framework-native security (validation, mass-assignment, policies, signed URLs, rate limiting), and Pest\u002FPHPUnit feature tests. NOT pure PHP language or toolchain work (that is `php`).\"\ntags: [laravel, php, eloquent, queues, pest, artisan]\nrecommends: [php, mysql, redis, api-design, secure-coding, testing-web]\norigin: risco\n---\n\n# Laravel (11\u002F12 era)\n\nBuild Laravel the way the framework ships **today** — Laravel 12 (released 2025-02-24,\nPHP 8.2–8.4), continuing the slimmed Laravel 11 skeleton. That means **no\n`app\u002FHttp\u002FKernel.php` and no `app\u002FConsole\u002FKernel.php`**: middleware, routing, exception\nhandling and providers are all configured in **`bootstrap\u002Fapp.php`**, and scheduled tasks\nlive in **`routes\u002Fconsole.php`**. Generate that structure, not 2019 Laravel.\n\nThis skill owns the **framework surface**: Eloquent, routing\u002Fcontrollers, queues, the\nartisan-shaped project, and in-framework Pest tests. The PHP *language and toolchain\nunderneath* (types, enums, Composer\u002FPSR-4, PHPStan, Pint) is the\n[..\u002Fphp\u002FSKILL.md](..\u002Fphp\u002FSKILL.md) skill — its boundary line literally reads \"NOT\nEloquent\u002FBlade\u002FArtisan (that is laravel)\"; this is the mirror.\n\n## Orient before you scaffold\n\nA wrong version assumption generates dead code. Detect the version and skeleton first.\n\n```bash\ncomposer show laravel\u002Fframework            # exact installed version\nls bootstrap\u002Fapp.php                        # present  -> L11\u002F12 slim skeleton\nls app\u002FHttp\u002FKernel.php 2>\u002Fdev\u002Fnull          # present  -> L10 or older (Kernel era)\nphp artisan --version                       # confirms runtime + version\n```\n\nIf `bootstrap\u002Fapp.php` exists and `app\u002FHttp\u002FKernel.php` does **not**, you are on L11\u002F12 —\nuse the modern idioms below. Then pick your path:\n\n| Situation | Do |\n|---|---|\n| Greenfield | `laravel new \u003Capp>`, then a starter kit: React (React 19 + TS + Inertia 2 + shadcn\u002Fui), Vue (Vue 3 + Inertia 2 + shadcn-vue), or Livewire (Livewire 3 + Volt + Flux UI). Optional WorkOS AuthKit for auth. |\n| Brownfield L11\u002F12 | Follow the repo's existing conventions; do not \"reorganize\" into folders it dropped. |\n| Pre-11 (Kernel era) | Migrate to `bootstrap\u002Fapp.php` deliberately; move Kernel middleware to `withMiddleware()`, schedule to `routes\u002Fconsole.php`. Treat as a project, not an inline tweak. |\n\n## The slim structure (where things live now)\n\n```text\nbootstrap\u002Fapp.php      # withRouting(), withMiddleware(), withExceptions(), withProviders()\nroutes\u002Fweb.php         # web routes (CSRF-protected, session)\nroutes\u002Fapi.php         # api routes (stateless) — present once you opt in\nroutes\u002Fconsole.php     # closures + the SCHEDULER (Schedule::command(...)->daily())\napp\u002FModels\u002F            # Eloquent models\napp\u002FHttp\u002FControllers\u002F  # thin controllers\napp\u002FHttp\u002FRequests\u002F     # Form Requests (validation + authorization)\napp\u002FJobs\u002F              # queued jobs\napp\u002FPolicies\u002F          # authorization policies\n```\n\n```php\n\u002F\u002F Bad: hunting for or editing app\u002FHttp\u002FKernel.php to register middleware (L11\u002F12 deleted it).\n\u002F\u002F Good: bootstrap\u002Fapp.php\nreturn Application::configure(basePath: dirname(__DIR__))\n    ->withRouting(web: __DIR__.'\u002F..\u002Froutes\u002Fweb.php', commands: __DIR__.'\u002F..\u002Froutes\u002Fconsole.php')\n    ->withMiddleware(function (Middleware $middleware) {\n        $middleware->alias(['subscribed' => EnsureUserIsSubscribed::class]);\n        $middleware->web(append: [TrackLastSeen::class]);\n    })\n    ->withExceptions(function (Exceptions $exceptions) {\n        $exceptions->dontReport(InvalidOrderException::class);\n    })->create();\n```\n\n## Eloquent\n\n**Mass assignment is the #1 Laravel footgun.** A model must declare an allowlist; an open\nblocklist on user input lets a request set any column (`is_admin`, `balance`).\n\n```php\n\u002F\u002F Bad: anything in the request body can be written, including columns you never meant to expose.\nclass Post extends Model {\n    protected $guarded = [];\n}\n\n\u002F\u002F Good: explicit allowlist. Casts give you typed attributes back out of the DB.\nclass Post extends Model {\n    protected $fillable = ['title', 'body', 'published_at'];\n\n    protected function casts(): array {\n        return [\n            'published_at' => 'datetime',\n            'status'       => PostStatus::class,   \u002F\u002F backed-enum cast\n            'meta'         => 'array',             \u002F\u002F json \u003C-> array\n            'api_token'    => 'encrypted',         \u002F\u002F at-rest encryption\n        ];\n    }\n\n    public function tags(): BelongsToMany { return $this->belongsToMany(Tag::class); }\n}\n```\n\n**N+1 is the most common Laravel performance bug** — a query per row instead of one. Eager\nload.\n\n```php\n\u002F\u002F Bad: 1 query for posts + 1 per post for its author = N+1.\nforeach (Post::all() as $post) { echo $post->author->name; }\n\n\u002F\u002F Good: eager load up front -> 2 queries total.\nforeach (Post::with('author')->get() as $post) { echo $post->author->name; }\n```\n\nMigrations define the schema; the `casts()` method (L11+ method form, not the old\n`$casts` array) maps columns to enums\u002Farrays\u002Fencrypted values. Relationship deep dives\n(polymorphic, has-many-through, scopes, observers, custom casts, accessors via the\n`Attribute` class) live in [references\u002Feloquent-patterns.md](references\u002Feloquent-patterns.md).\n\n## Routing, controllers, validation\n\nKeep controllers thin: they take a validated request, call a service\u002Fmodel, return a\nresponse. Push branching logic out of routes — **business logic in `routes\u002Fweb.php` is\nuntestable and unreusable**.\n\n**Form Requests do validation AND authorization in one object** — the `authorize()` gate\nruns before `rules()`, so an unauthorized request never reaches your validation or\ncontroller.\n\n```php\n\u002F\u002F app\u002FHttp\u002FRequests\u002FStoreOrderRequest.php\nfinal class StoreOrderRequest extends FormRequest {\n    public function authorize(): bool {\n        return $this->user()->can('create', Order::class);   \u002F\u002F policy check, before rules\n    }\n\n    public function rules(): array {\n        return [\n            'sku'      => ['required', 'string', 'exists:products,sku'],\n            'quantity' => ['required', 'integer', 'min:1', 'max:100'],\n        ];\n    }\n}\n\n\u002F\u002F Controller: route-model binding + the Form Request = a tiny method.\npublic function store(StoreOrderRequest $request): RedirectResponse {\n    $order = Order::create($request->validated());          \u002F\u002F only allow-listed, validated data\n    ProcessOrder::dispatch($order);\n    return to_route('orders.show', $order);\n}\n```\n\nFor JSON APIs, shape output with **API Resources** (`JsonResource`). The transport\n*contract* — resource naming, versioning, status-code semantics, pagination shape — is the\n**api-design** skill, not this one; this skill covers implementing it in Laravel.\n\n## Queues & scheduling\n\nA job that implements `ShouldQueue` is pushed to the queue and runs out-of-band instead of\ninline — that is what gets a slow email\u002Fpayment off the request cycle.\n\n```php\nfinal class ProcessOrder implements ShouldQueue {\n    use Queueable, Batchable;\n\n    public int $tries = 3;                       \u002F\u002F attempts before it lands in failed_jobs\n    public int $timeout = 120;                   \u002F\u002F seconds before the worker kills it\n\n    public function backoff(): array { return [10, 60, 300]; }  \u002F\u002F exponential-ish retry spacing\n\n    public function __construct(public Order $order) {}\n\n    public function handle(): void {\n        if ($this->batch()?->cancelled()) return; \u002F\u002F respect a cancelled batch\n        \u002F\u002F ... charge, fulfil ...\n    }\n}\n\nProcessOrder::dispatch($order);                   \u002F\u002F queued (or inline if driver is sync)\n```\n\nBatches let you fan out and react when the group finishes; `allowFailures()` keeps the\nbatch going when individual jobs fail.\n\n```php\nBus::batch([new ProcessOrder($a), new ProcessOrder($b)])\n    ->allowFailures()\n    ->then(fn (Batch $b) => Log::info(\"done: {$b->totalJobs}\"))\n    ->dispatch();\n```\n\n**Driver choice:**\n\n| Need | Use |\n|---|---|\n| Simple, low volume, no extra infra | `database` driver (a `jobs` table) |\n| High throughput + a dashboard (retries, runtime, failures) | **Redis + Horizon** — Horizon manages the workers and gives you the monitor |\n\nSchedule recurring work in `routes\u002Fconsole.php` (the L11\u002F12 home for the scheduler — there\nis no `app\u002FConsole\u002FKernel.php`):\n\n```php\n\u002F\u002F routes\u002Fconsole.php\nSchedule::command('orders:reconcile')->dailyAt('02:00');\nSchedule::job(new PruneStaleCarts)->hourly();\n```\n\nWorker deployment, Horizon config, the retry\u002Fbackoff\u002Ftimeout matrix, `failed_jobs` +\n`queue:retry`, and supervisor\u002F`queue:work` flags are in\n[references\u002Fqueues-and-scheduling.md](references\u002Fqueues-and-scheduling.md).\n\n## Security (framework-native)\n\n| Control | Use | Why |\n|---|---|---|\n| Validation | Form Request `rules()` | reject malformed input at the edge, before the controller |\n| Mass-assignment guard | `$fillable` allowlist (see Eloquent) | stops a request writing columns you never exposed |\n| Authorization | Policies + Gates, `$user->can(...)`, `authorize()` | keeps authz out of controllers and consistent |\n| Tamper-proof links | signed URLs (`URL::signedRoute`, `signed` middleware) | unsubscribe\u002Fverify links that can't be forged |\n| Abuse limiting | rate limiting (`throttle` middleware, `RateLimiter::for`) | caps brute-force \u002F scraping per user or IP |\n| Secrets at rest | `Hash::make`\u002F`Hash::check` for passwords, `Crypt` for reversible data | bcrypt\u002Fargon2 hashing; never store plaintext |\n\nCSRF protection is automatic on `web` routes; do not disable it. **Read config through\n`config()`, never `env()` outside `config\u002F*.php`** — once configs are cached (`config:cache`\nin prod) `env()` returns `null` everywhere else. Cross-stack OWASP\u002Fthreat-modeling is the\n**secure-coding** skill; the table above is the framework-native layer this skill owns.\n\n## Testing\n\nPest is the default runner in new Laravel apps (PHPUnit still fully supported). Use\n`RefreshDatabase` for a clean schema per test and model factories for data.\n\n```php\nuses(RefreshDatabase::class);\n\nit('processes a paid order', function () {\n    $user = User::factory()->create();\n    $this->actingAs($user)\n        ->post('\u002Forders', ['sku' => 'ABC', 'quantity' => 2])\n        ->assertRedirect();\n\n    $this->assertDatabaseHas('orders', ['sku' => 'ABC', 'quantity' => 2]);\n});\n```\n\n**The sync-driver gotcha.** Tests use the `sync` queue driver by default, so a dispatched\njob runs **inline** during the test — it does not sit on a queue. If you assert \"the email\nwas sent\" you are accidentally testing execution. To test that work was *dispatched*, fake\nthe queue first:\n\n```php\nit('dispatches order processing', function () {\n    Queue::fake();                               \u002F\u002F jobs are now recorded, not run\n    $order = Order::factory()->create();\n\n    ProcessOrder::dispatch($order);\n\n    Queue::assertPushed(ProcessOrder::class);    \u002F\u002F assert dispatch, not side effects\n});\n```\n\n`Http::fake()` and `Event::fake()` work the same way for outbound HTTP and events.\nCross-stack browser\u002FE2E (Playwright\u002FCypress) strategy is the **testing-web** skill; this\nskill covers in-framework Pest\u002FPHPUnit feature and unit tests.\n\n## Ecosystem (reach for these by name)\n\nPennant (feature flags \u002F A-B), Pulse (real-time perf: slow queries, job throughput),\nFolio (page-based routing), Horizon (Redis queue dashboard). First-party — prefer them\nover rolling your own.\n\n## Anti-patterns\n\n| Pattern | Why it is bad | Do instead |\n|---|---|---|\n| `protected $guarded = []` on a user-facing model | any request column becomes mass-assignable (`is_admin`, `balance`) | explicit `$fillable` allowlist |\n| Hunting for \u002F re-creating `app\u002FHttp\u002FKernel.php` on L11\u002F12 | the file was deleted; your middleware never registers | configure in `bootstrap\u002Fapp.php` `withMiddleware()` |\n| Lazy access inside a loop\u002FBlade (`$post->author` per row) | N+1 — one query per row | eager load with `with()` |\n| Fat controllers \u002F logic in `routes\u002Fweb.php` | untestable, unreusable, no authz boundary | thin controller + Form Request + service\u002Fmodel |\n| Asserting a queued job's *side effects* in a test | sync driver runs it inline — you test execution, not dispatch | `Queue::fake()` + `Queue::assertPushed()` |\n| `env()` outside `config\u002F*.php` | returns `null` once `config:cache` runs in prod | read via `config()`; `env()` only inside config files |\n| `$tries` unset on a flaky job | one transient failure = permanent failure | set `$tries` + `backoff()` |\n| Committing real secrets in `.env` | leaks credentials into history | `.env` is git-ignored; commit `.env.example` only |\n| Old `$casts = [...]` array (deprecated form) | misses the L11+ `casts()` method idioms | the `casts(): array` method |\n\n## Verify\n\nRun [scripts\u002Fverify.sh](scripts\u002Fverify.sh) from a Laravel project root. It validates\n`composer.json`, checks the framework version, runs Pint (style, read-only `--test`) and\nthe test runner (Pest\u002F`artisan test`) if present, and greps for `protected $guarded = []`\nunder `app\u002FModels`. It degrades gracefully — prints a skip notice and exits 0 — when there\nis no Laravel project or no `vendor\u002F` dir, so it never blocks a non-Laravel repo.\n\n## References & siblings\n\n- [references\u002Feloquent-patterns.md](references\u002Feloquent-patterns.md) — relationship catalog\n  (polymorphic, has-many-through), eager-load strategies, query\u002Flocal scopes, observers,\n  attribute casts + custom casts, accessors\u002Fmutators via the `Attribute` class.\n- [references\u002Fqueues-and-scheduling.md](references\u002Fqueues-and-scheduling.md) — driver\n  selection, Horizon install\u002Fconfig, retry\u002Fbackoff\u002Ftimeout matrix, batch chaining,\n  `failed_jobs` + `queue:retry`, worker deployment (supervisor, `queue:work` flags),\n  graceful restarts.\n- PHP language\u002Ftoolchain underneath Laravel: [..\u002Fphp\u002FSKILL.md](..\u002Fphp\u002FSKILL.md).\n- Cross-stack OWASP\u002Fthreat-modeling: [..\u002Fsecure-coding\u002FSKILL.md](..\u002Fsecure-coding\u002FSKILL.md).\n- API contract design, MySQL\u002FRedis server tuning, browser E2E strategy: the **api-design**,\n  **mysql** \u002F **redis**, and **testing-web** skills respectively.\n","# Laravel (11\u002F12 era)\n\nBuild Laravel the way the framework ships **today** — Laravel 12 (released 2025-02-24,\nPHP 8.2–8.4), continuing the slimmed Laravel 11 skeleton. That means **no\n`app\u002FHttp\u002FKernel.php` and no `app\u002FConsole\u002FKernel.php`**: middleware, routing, exception\nhandling and providers are all configured in **`bootstrap\u002Fapp.php`**, and scheduled tasks\nlive in **`routes\u002Fconsole.php`**. Generate that structure, not 2019 Laravel.\n\nThis skill owns the **framework surface**: Eloquent, routing\u002Fcontrollers, queues, the\nartisan-shaped project, and in-framework Pest tests. The PHP *language and toolchain\nunderneath* (types, enums, Composer\u002FPSR-4, PHPStan, Pint) is the\n[..\u002Fphp\u002FSKILL.md](..\u002Fphp\u002FSKILL.md) skill — its boundary line literally reads \"NOT\nEloquent\u002FBlade\u002FArtisan (that is laravel)\"; this is the mirror.\n\n## Orient before you scaffold\n\nA wrong version assumption generates dead code. Detect the version and skeleton first.\n\n```bash\ncomposer show laravel\u002Fframework            # exact installed version\nls bootstrap\u002Fapp.php                        # present  -> L11\u002F12 slim skeleton\nls app\u002FHttp\u002FKernel.php 2>\u002Fdev\u002Fnull          # present  -> L10 or older (Kernel era)\nphp artisan --version                       # confirms runtime + version\n```\n\nIf `bootstrap\u002Fapp.php` exists and `app\u002FHttp\u002FKernel.php` does **not**, you are on L11\u002F12 —\nuse the modern idioms below. Then pick your path:\n\n| Situation | Do |\n|---|---|\n| Greenfield | `laravel new \u003Capp>`, then a starter kit: React (React 19 + TS + Inertia 2 + shadcn\u002Fui), Vue (Vue 3 + Inertia 2 + shadcn-vue), or Livewire (Livewire 3 + Volt + Flux UI). Optional WorkOS AuthKit for auth. |\n| Brownfield L11\u002F12 | Follow the repo's existing conventions; do not \"reorganize\" into folders it dropped. |\n| Pre-11 (Kernel era) | Migrate to `bootstrap\u002Fapp.php` deliberately; move Kernel middleware to `withMiddleware()`, schedule to `routes\u002Fconsole.php`. Treat as a project, not an inline tweak. |\n\n## The slim structure (where things live now)\n\n```text\nbootstrap\u002Fapp.php      # withRouting(), withMiddleware(), withExceptions(), withProviders()\nroutes\u002Fweb.php         # web routes (CSRF-protected, session)\nroutes\u002Fapi.php         # api routes (stateless) — present once you opt in\nroutes\u002Fconsole.php     # closures + the SCHEDULER (Schedule::command(...)->daily())\napp\u002FModels\u002F            # Eloquent models\napp\u002FHttp\u002FControllers\u002F  # thin controllers\napp\u002FHttp\u002FRequests\u002F     # Form Requests (validation + authorization)\napp\u002FJobs\u002F              # queued jobs\napp\u002FPolicies\u002F          # authorization policies\n```\n\n```php\n\u002F\u002F Bad: hunting for or editing app\u002FHttp\u002FKernel.php to register middleware (L11\u002F12 deleted it).\n\u002F\u002F Good: bootstrap\u002Fapp.php\nreturn Application::configure(basePath: dirname(__DIR__))\n    ->withRouting(web: __DIR__.'\u002F..\u002Froutes\u002Fweb.php', commands: __DIR__.'\u002F..\u002Froutes\u002Fconsole.php')\n    ->withMiddleware(function (Middleware $middleware) {\n        $middleware->alias(['subscribed' => EnsureUserIsSubscribed::class]);\n        $middleware->web(append: [TrackLastSeen::class]);\n    })\n    ->withExceptions(function (Exceptions $exceptions) {\n        $exceptions->dontReport(InvalidOrderException::class);\n    })->create();\n```\n\n## Eloquent\n\n**Mass assignment is the #1 Laravel footgun.** A model must declare an allowlist; an open\nblocklist on user input lets a request set any column (`is_admin`, `balance`).\n\n```php\n\u002F\u002F Bad: anything in the request body can be written, including columns you never meant to expose.\nclass Post extends Model {\n    protected $guarded = [];\n}\n\n\u002F\u002F Good: explicit allowlist. Casts give you typed attributes back out of the DB.\nclass Post extends Model {\n    protected $fillable = ['title', 'body', 'published_at'];\n\n    protected function casts(): array {\n        return [\n            'published_at' => 'datetime',\n            'status'       => PostStatus::class,   \u002F\u002F backed-enum cast\n            'meta'         => 'array',             \u002F\u002F json \u003C-> array\n            'api_token'    => 'encrypted',         \u002F\u002F at-rest encryption\n        ];\n    }\n\n    public function tags(): BelongsToMany { return $this->belongsToMany(Tag::class); }\n}\n```\n\n**N+1 is the most common Laravel performance bug** — a query per row instead of one. Eager\nload.\n\n```php\n\u002F\u002F Bad: 1 query for posts + 1 per post for its author = N+1.\nforeach (Post::all() as $post) { echo $post->author->name; }\n\n\u002F\u002F Good: eager load up front -> 2 queries total.\nforeach (Post::with('author')->get() as $post) { echo $post->author->name; }\n```\n\nMigrations define the schema; the `casts()` method (L11+ method form, not the old\n`$casts` array) maps columns to enums\u002Farrays\u002Fencrypted values. Relationship deep dives\n(polymorphic, has-many-through, scopes, observers, custom casts, accessors via the\n`Attribute` class) live in [references\u002Feloquent-patterns.md](references\u002Feloquent-patterns.md).\n\n## Routing, controllers, validation\n\nKeep controllers thin: they take a validated request, call a service\u002Fmodel, return a\nresponse. Push branching logic out of routes — **business logic in `routes\u002Fweb.php` is\nuntestable and unreusable**.\n\n**Form Requests do validation AND authorization in one object** — the `authorize()` gate\nruns before `rules()`, so an unauthorized request never reaches your validation or\ncontroller.\n\n```php\n\u002F\u002F app\u002FHttp\u002FRequests\u002FStoreOrderRequest.php\nfinal class StoreOrderRequest extends FormRequest {\n    public function authorize(): bool {\n        return $this->user()->can('create', Order::class);   \u002F\u002F policy check, before rules\n    }\n\n    public function rules(): array {\n        return [\n            'sku'      => ['required', 'string', 'exists:products,sku'],\n            'quantity' => ['required', 'integer', 'min:1', 'max:100'],\n        ];\n    }\n}\n\n\u002F\u002F Controller: route-model binding + the Form Request = a tiny method.\npublic function store(StoreOrderRequest $request): RedirectResponse {\n    $order = Order::create($request->validated());          \u002F\u002F only allow-listed, validated data\n    ProcessOrder::dispatch($order);\n    return to_route('orders.show', $order);\n}\n```\n\nFor JSON APIs, shape output with **API Resources** (`JsonResource`). The transport\n*contract* — resource naming, versioning, status-code semantics, pagination shape — is the\n**api-design** skill, not this one; this skill covers implementing it in Laravel.\n\n## Queues & scheduling\n\nA job that implements `ShouldQueue` is pushed to the queue and runs out-of-band instead of\ninline — that is what gets a slow email\u002Fpayment off the request cycle.\n\n```php\nfinal class ProcessOrder implements ShouldQueue {\n    use Queueable, Batchable;\n\n    public int $tries = 3;                       \u002F\u002F attempts before it lands in failed_jobs\n    public int $timeout = 120;                   \u002F\u002F seconds before the worker kills it\n\n    public function backoff(): array { return [10, 60, 300]; }  \u002F\u002F exponential-ish retry spacing\n\n    public function __construct(public Order $order) {}\n\n    public function handle(): void {\n        if ($this->batch()?->cancelled()) return; \u002F\u002F respect a cancelled batch\n        \u002F\u002F ... charge, fulfil ...\n    }\n}\n\nProcessOrder::dispatch($order);                   \u002F\u002F queued (or inline if driver is sync)\n```\n\nBatches let you fan out and react when the group finishes; `allowFailures()` keeps the\nbatch going when individual jobs fail.\n\n```php\nBus::batch([new ProcessOrder($a), new ProcessOrder($b)])\n    ->allowFailures()\n    ->then(fn (Batch $b) => Log::info(\"done: {$b->totalJobs}\"))\n    ->dispatch();\n```\n\n**Driver choice:**\n\n| Need | Use |\n|---|---|\n| Simple, low volume, no extra infra | `database` driver (a `jobs` table) |\n| High throughput + a dashboard (retries, runtime, failures) | **Redis + Horizon** — Horizon manages the workers and gives you the monitor |\n\nSchedule recurring work in `routes\u002Fconsole.php` (the L11\u002F12 home for the scheduler — there\nis no `app\u002FConsole\u002FKernel.php`):\n\n```php\n\u002F\u002F routes\u002Fconsole.php\nSchedule::command('orders:reconcile')->dailyAt('02:00');\nSchedule::job(new PruneStaleCarts)->hourly();\n```\n\nWorker deployment, Horizon config, the retry\u002Fbackoff\u002Ftimeout matrix, `failed_jobs` +\n`queue:retry`, and supervisor\u002F`queue:work` flags are in\n[references\u002Fqueues-and-scheduling.md](references\u002Fqueues-and-scheduling.md).\n\n## Security (framework-native)\n\n| Control | Use | Why |\n|---|---|---|\n| Validation | Form Request `rules()` | reject malformed input at the edge, before the controller |\n| Mass-assignment guard | `$fillable` allowlist (see Eloquent) | stops a request writing columns you never exposed |\n| Authorization | Policies + Gates, `$user->can(...)`, `authorize()` | keeps authz out of controllers and consistent |\n| Tamper-proof links | signed URLs (`URL::signedRoute`, `signed` middleware) | unsubscribe\u002Fverify links that can't be forged |\n| Abuse limiting | rate limiting (`throttle` middleware, `RateLimiter::for`) | caps brute-force \u002F scraping per user or IP |\n| Secrets at rest | `Hash::make`\u002F`Hash::check` for passwords, `Crypt` for reversible data | bcrypt\u002Fargon2 hashing; never store plaintext |\n\nCSRF protection is automatic on `web` routes; do not disable it. **Read config through\n`config()`, never `env()` outside `config\u002F*.php`** — once configs are cached (`config:cache`\nin prod) `env()` returns `null` everywhere else. Cross-stack OWASP\u002Fthreat-modeling is the\n**secure-coding** skill; the table above is the framework-native layer this skill owns.\n\n## Testing\n\nPest is the default runner in new Laravel apps (PHPUnit still fully supported). Use\n`RefreshDatabase` for a clean schema per test and model factories for data.\n\n```php\nuses(RefreshDatabase::class);\n\nit('processes a paid order', function () {\n    $user = User::factory()->create();\n    $this->actingAs($user)\n        ->post('\u002Forders', ['sku' => 'ABC', 'quantity' => 2])\n        ->assertRedirect();\n\n    $this->assertDatabaseHas('orders', ['sku' => 'ABC', 'quantity' => 2]);\n});\n```\n\n**The sync-driver gotcha.** Tests use the `sync` queue driver by default, so a dispatched\njob runs **inline** during the test — it does not sit on a queue. If you assert \"the email\nwas sent\" you are accidentally testing execution. To test that work was *dispatched*, fake\nthe queue first:\n\n```php\nit('dispatches order processing', function () {\n    Queue::fake();                               \u002F\u002F jobs are now recorded, not run\n    $order = Order::factory()->create();\n\n    ProcessOrder::dispatch($order);\n\n    Queue::assertPushed(ProcessOrder::class);    \u002F\u002F assert dispatch, not side effects\n});\n```\n\n`Http::fake()` and `Event::fake()` work the same way for outbound HTTP and events.\nCross-stack browser\u002FE2E (Playwright\u002FCypress) strategy is the **testing-web** skill; this\nskill covers in-framework Pest\u002FPHPUnit feature and unit tests.\n\n## Ecosystem (reach for these by name)\n\nPennant (feature flags \u002F A-B), Pulse (real-time perf: slow queries, job throughput),\nFolio (page-based routing), Horizon (Redis queue dashboard). First-party — prefer them\nover rolling your own.\n\n## Anti-patterns\n\n| Pattern | Why it is bad | Do instead |\n|---|---|---|\n| `protected $guarded = []` on a user-facing model | any request column becomes mass-assignable (`is_admin`, `balance`) | explicit `$fillable` allowlist |\n| Hunting for \u002F re-creating `app\u002FHttp\u002FKernel.php` on L11\u002F12 | the file was deleted; your middleware never registers | configure in `bootstrap\u002Fapp.php` `withMiddleware()` |\n| Lazy access inside a loop\u002FBlade (`$post->author` per row) | N+1 — one query per row | eager load with `with()` |\n| Fat controllers \u002F logic in `routes\u002Fweb.php` | untestable, unreusable, no authz boundary | thin controller + Form Request + service\u002Fmodel |\n| Asserting a queued job's *side effects* in a test | sync driver runs it inline — you test execution, not dispatch | `Queue::fake()` + `Queue::assertPushed()` |\n| `env()` outside `config\u002F*.php` | returns `null` once `config:cache` runs in prod | read via `config()`; `env()` only inside config files |\n| `$tries` unset on a flaky job | one transient failure = permanent failure | set `$tries` + `backoff()` |\n| Committing real secrets in `.env` | leaks credentials into history | `.env` is git-ignored; commit `.env.example` only |\n| Old `$casts = [...]` array (deprecated form) | misses the L11+ `casts()` method idioms | the `casts(): array` method |\n\n## Verify\n\nRun [scripts\u002Fverify.sh](scripts\u002Fverify.sh) from a Laravel project root. It validates\n`composer.json`, checks the framework version, runs Pint (style, read-only `--test`) and\nthe test runner (Pest\u002F`artisan test`) if present, and greps for `protected $guarded = []`\nunder `app\u002FModels`. It degrades gracefully — prints a skip notice and exits 0 — when there\nis no Laravel project or no `vendor\u002F` dir, so it never blocks a non-Laravel repo.\n\n## References & siblings\n\n- [references\u002Feloquent-patterns.md](references\u002Feloquent-patterns.md) — relationship catalog\n  (polymorphic, has-many-through), eager-load strategies, query\u002Flocal scopes, observers,\n  attribute casts + custom casts, accessors\u002Fmutators via the `Attribute` class.\n- [references\u002Fqueues-and-scheduling.md](references\u002Fqueues-and-scheduling.md) — driver\n  selection, Horizon install\u002Fconfig, retry\u002Fbackoff\u002Ftimeout matrix, batch chaining,\n  `failed_jobs` + `queue:retry`, worker deployment (supervisor, `queue:work` flags),\n  graceful restarts.\n- PHP language\u002Ftoolchain underneath Laravel: [..\u002Fphp\u002FSKILL.md](..\u002Fphp\u002FSKILL.md).\n- Cross-stack OWASP\u002Fthreat-modeling: [..\u002Fsecure-coding\u002FSKILL.md](..\u002Fsecure-coding\u002FSKILL.md).\n- API contract design, MySQL\u002FRedis server tuning, browser E2E strategy: the **api-design**,\n  **mysql** \u002F **redis**, and **testing-web** skills respectively.\n",{"name":5,"tags":24,"origin":30,"recommends":31,"description":7},[5,25,26,27,28,29],"php","eloquent","queues","pest","artisan","risco",[25,32,33,34,35,36],"mysql","redis","api-design","secure-coding","testing-web","main","d69096e239f2a89aabc2cd078c47664a9d3b1e11","07-后端与架构\u002Flaravel",3,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts","https:\u002F\u002Fgithub.com\u002Flza6","个人vx：Tf00798\r\n个人✈：@TFGY999","2026-10-08 14:29:22",{"source":8,"skillName":5,"commands":46,"prompt":56,"zipAvailable":57},[47,50,53],{"tool":48,"command":49},"npx","npx skills add lza6\u002FArmor-piercing-system-prompts --skill laravel",{"tool":51,"command":52},"bunx","bunx skills add lza6\u002FArmor-piercing-system-prompts --skill laravel",{"tool":54,"command":55},"pnpm","pnpm dlx skills add lza6\u002FArmor-piercing-system-prompts --skill laravel","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Flaravel\u002FSKILL.md",true,[59,65,69,73],{"path":60,"resourceType":61,"resourceTypeDesc":62,"sizeBytes":63,"sourceHtmlUrl":64},"evals\u002Fcases.yaml","REFERENCE","参考文档",3313,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Flaravel\u002Fevals\u002Fcases.yaml",{"path":66,"resourceType":61,"resourceTypeDesc":62,"sizeBytes":67,"sourceHtmlUrl":68},"evals\u002FREADME.md",763,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Flaravel\u002Fevals\u002FREADME.md",{"path":70,"resourceType":61,"resourceTypeDesc":62,"sizeBytes":71,"sourceHtmlUrl":72},"references\u002Feloquent-patterns.md",4955,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Flaravel\u002Freferences\u002Feloquent-patterns.md",{"path":74,"resourceType":61,"resourceTypeDesc":62,"sizeBytes":75,"sourceHtmlUrl":76},"references\u002Fqueues-and-scheduling.md",5556,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Flaravel\u002Freferences\u002Fqueues-and-scheduling.md",[78,85,90,97,104,111],{"skillNo":79,"name":80,"nameZh":6,"description":81,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":82,"categories":83,"keywords":84,"publishedAt":19},"01M7FFG485KY83TD6HSC4YPCMC","obsidian-clipper-template-creator","Guide for creating templates for the Obsidian Web Clipper. Use when you want to create a new clipping template, understand available variables, or format clipped content.","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobsidian-clipper-template-creator\u002FSKILL.md",[],[],{"skillNo":86,"name":80,"nameZh":6,"description":81,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":87,"categories":88,"keywords":89,"publishedAt":19},"01M7FFG0T6AZ0STEJPSB3CX84K","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobsidian-clipper-template-creator-antigravity-awesome-skills-main\u002FSKILL.md",[],[],{"skillNo":91,"name":92,"nameZh":6,"description":93,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":94,"categories":95,"keywords":96,"publishedAt":19},"01M7FFFY0QEM14SKWPDYGMXM2P","python-api","Programmatic Object-Detection-Metrics API guidance for BoundingBox, BoundingBoxes, Evaluator, enums, coordinate conversion, AP\u002FmAP semantics, and source-style import diagnostics.","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobject-detection-metrics\u002Fsub-skills\u002Fpython-api\u002FSKILL.md",[],[],{"skillNo":98,"name":99,"nameZh":6,"description":100,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":101,"categories":102,"keywords":103,"publishedAt":19},"01M7FFFVZQZ2GJ0C0TGP7JHD20","file-evaluation","Folder-based PASCAL VOC AP\u002FmAP evaluation from ground-truth and detection text files.","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobject-detection-metrics\u002Fsub-skills\u002Ffile-evaluation\u002FSKILL.md",[],[],{"skillNo":105,"name":106,"nameZh":6,"description":107,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":108,"categories":109,"keywords":110,"publishedAt":19},"01M7FFFSFNYSE77SJ6PE1CK2DA","object-detection-metrics","Guides legacy Object-Detection-Metrics PASCAL VOC AP\u002FmAP evaluation from detection text folders and direct Python API classes.","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobject-detection-metrics\u002FSKILL.md",[],[],{"skillNo":112,"name":113,"nameZh":6,"description":114,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":115,"categories":116,"keywords":117,"publishedAt":19},"01M7FFFP0GCK1RVXBCPQ8APBMT","nx-workspace-patterns","Configure and optimize Nx monorepo workspaces. Use when setting up Nx, configuring project boundaries, optimizing build caching, or implementing affected commands.","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fnx-workspace-patterns\u002FSKILL.md",[],[]]