laravel-lomkit-rest-api
Step 6 of the pipeline (WORKFLOW.md). The package turns a declared Resource into a small fixed set of
endpoints. Its safety comes entirely from declaration: what is not declared is refused. Most defects in
this stack are code that steps around that declaration. Sits under skills/laravel-conventions §6 (HTTP
surface), which prefers the package's filters over hand-built endpoints; it does not apply to an Inertia
project (skills/inertia-conventions §4).
Special status. New block, 🟡: never run on real work in house. Checked on 2026-10-20 against the
guidance file the package itself ships. Requirements at that reading (composer.json): PHP 8.2+, Laravel 12 or 13. Method and config names are version facts;
re-read the package documentation for the pinned version (skills/source-freshness).
When
A file under the app's REST resources or controllers directory, a Rest::resource(...) line, a Lomkit\Rest
import, or a client payload with search, mutate, filters, includes, gates or instructions.
Steps
- Extend, do not parallel. For a model the package already exposes, add a Resource field, an action or
an instruction. Do not add a plain resource route for the same model: the two authorisation paths drift.
A project without the package is not pushed toward it; recommend it only where rich filtering, batch
mutation or schema introspection clearly fit, and name the dependency without installing it.
- Whitelist by declaration. The Resource's
fields, relations, scopes, actions and instructions
are the whole surface; a new column on the table is not exposed until it is listed. Narrow any list per
request or per permission through the request argument every method receives. Relations use the package's
own relation classes pointing at a Resource, never the Eloquent relation classes or a model.
- Baseline constraints live in the base resource's query hooks (search, mutate, destroy, restore,
force-delete queries): tenant scoping and visibility are set there once. A change that touches those hooks
preserves what they already apply (
skills/laravel-tenant-context-by-default).
- Policies are the authority. Every exposed model needs a policy with
viewAny, view, create,
update, replicate, delete, restore, forceDelete, and attach{Model} / detach{Model} for each
many-to-many relation that may be mutated; a missing method blocks the operation. Never switch the
authorisation flag off to unblock a test: write the policy (skills/laravel-permissions-not-roles).
Authorisation results are cached per user and resource for a few minutes by default, so a policy change
looks ineffective until the cache is disabled or expires; check that before debugging the policy.
- Gates are a client convenience, not enforcement. The client may ask the server to evaluate listed
abilities per row and embed the result. The server still enforces on the real call.
- Mutation is batched but all-or-nothing on authorisation. One denied item fails the whole batch. A
response lists affected ids, not models: re-query for the record. Through-relations can be read, never
mutated; chain through the intermediate relation. Constrain relation writes with the required and
prohibited-on-create/update helpers rather than ad hoc validation.
- Actions for writes, instructions for reads. Do not write a custom controller method for a use case
the package models. An action declares how it is targeted: standalone (no models), classic (whatever the
search resolves, every model if search is omitted), or targeted (explicit ids, required, capped, ids the
caller cannot see are skipped). Give a destructive or bulk action the targeted form so omitting the
argument is a validation error (422), not a mass update, and lower the id cap (
$maxResources, default
- when the blast radius should be smaller. Standalone and targeted are mutually exclusive and combining them throws. An action's field
payload is a list of name and value pairs, not an object. A queued action dispatches one job per chunk of models (100 by default).
- Includes are not nested. An include takes filters, sorts, scopes, limit and selects but not another
include; go deeper with one include per level and register the chained relation on the intermediate
resource. An include alias must be an identifier, unique, and not collide with a field, relation or the
gates key. The shipped guidance is inconsistent here (it also speaks of a "nested include" for dotted
relation paths): check the installed version before relying on dotted paths or aliases on them.
- A custom response class can undo the whitelist. Mapping from the model directly bypasses field
shaping and authorisation. Use it only to reshape output, reading through the same allowed fields.
- Soft-delete routes are opt-in at the route even when the model uses soft deletes.
- Every request is JSON. The package refuses a request without the JSON accept header. Live form
validation uses the precognition header when enabled in configuration, which is off by default; a valid
precognitive request answers 204 and an invalid one 422 (
skills/laravel-precognitive-request-scoping).
- Document with the existing path. The package integrates with an OpenAPI generator extension; the
built-in Swagger path is being superseded, so no new customisation there for new work.
- The free-text
text search key needs a Scout-searchable model. The shipped guidance says the key requires
a model that uses the searchable trait; check the model before exposing a text search.
Output / checkpoint
No exposed model without a full policy, no route for a package-managed model outside Rest::resource, no
bulk action that can run unscoped, and no field exposed that is not listed on purpose. Checked at gate (7)
and review (8).
Guardrails
No comments in the code produced. New and changed code only (skills/code-baseline §0). A genuine defect in
the package goes to its tracker with a reproduction, not into an app-local shim
(skills/code-baseline §7 on customising a third party).
Origin
Rewritten from the laravel-rest-api skill file shipped inside lomkit/laravel-rest-api itself (MIT, LICENSE
read 2026-10-20, default branch pushed 2026-10-13; requirements from its composer.json): declaration whitelist,
hook layers, policy and gate model (including the five-minute authorisation cache), mutation all-or-nothing and
id-only responses, action targeting states, id cap and chunk size, include and alias rules, soft-delete opt-in,
precognition and JSON header, OpenAPI path, the custom-response warning and the Scout text key. Every step
was re-matched against that file on 2026-10-20. Not confirmed elsewhere: the documentation site
(laravel-rest-api.lomkit.com) was opened but the pages on includes returned 404, so the include rules rest on
that one file, which contradicts itself on dotted paths. Steps 1 (extend rather than parallel, and the advice
not to push the package onto a project without it) and 3's reference to tenant scoping are our own guidance.
Mechanisms only, rewritten in our words.
Independent verification 2026-10-21: 16 checked (shipped guidance file plus package source and config), 16 matched, 0 corrected, 0 unverified.
1---2name: laravel-lomkit-rest-api3description: "Use when a Laravel project exposes models through lomkit/laravel-rest-api (Resources, Controllers, Rest::resource routes, actions, instructions, search and mutate payloads): what the package whitelists, how its authorisation layers work, and the mistakes that bypass them. Not for Inertia pages or plain controllers."4metadata:5 source: https://skillmd.com/skills/techmefr/laravel-lomkit-rest-api6---78# laravel-lomkit-rest-api910Step 6 of the pipeline (`WORKFLOW.md`). The package turns a declared Resource into a small fixed set of11endpoints. Its safety comes entirely from **declaration**: what is not declared is refused. Most defects in12this stack are code that steps around that declaration. Sits under `skills/laravel-conventions` §6 (HTTP13surface), which prefers the package's filters over hand-built endpoints; it does not apply to an Inertia14project (`skills/inertia-conventions` §4).1516**Special status.** New block, 🟡: never run on real work in house. Checked on 2026-10-20 against the17guidance file the package itself ships. Requirements at that reading (`composer.json`): PHP 8.2+, Laravel 12 or 13. Method and config names are version facts;18re-read the package documentation for the pinned version (`skills/source-freshness`).1920## When21A file under the app's REST resources or controllers directory, a `Rest::resource(...)` line, a `Lomkit\Rest`22import, or a client payload with `search`, `mutate`, `filters`, `includes`, `gates` or `instructions`.2324## Steps251. **Extend, do not parallel.** For a model the package already exposes, add a Resource field, an action or26 an instruction. Do not add a plain resource route for the same model: the two authorisation paths drift.27 A project without the package is not pushed toward it; recommend it only where rich filtering, batch28 mutation or schema introspection clearly fit, and name the dependency without installing it.292. **Whitelist by declaration.** The Resource's `fields`, `relations`, `scopes`, `actions` and `instructions`30 are the whole surface; a new column on the table is not exposed until it is listed. Narrow any list per31 request or per permission through the request argument every method receives. Relations use the package's32 own relation classes pointing at a **Resource**, never the Eloquent relation classes or a model.333. **Baseline constraints live in the base resource's query hooks** (search, mutate, destroy, restore,34 force-delete queries): tenant scoping and visibility are set there once. A change that touches those hooks35 preserves what they already apply (`skills/laravel-tenant-context-by-default`).364. **Policies are the authority.** Every exposed model needs a policy with `viewAny`, `view`, `create`,37 `update`, `replicate`, `delete`, `restore`, `forceDelete`, and `attach{Model}` / `detach{Model}` for each38 many-to-many relation that may be mutated; a missing method blocks the operation. Never switch the39 authorisation flag off to unblock a test: write the policy (`skills/laravel-permissions-not-roles`).40 Authorisation results are cached per user and resource for a few minutes by default, so a policy change41 looks ineffective until the cache is disabled or expires; check that before debugging the policy.425. **Gates are a client convenience, not enforcement.** The client may ask the server to evaluate listed43 abilities per row and embed the result. The server still enforces on the real call.446. **Mutation is batched but all-or-nothing on authorisation.** One denied item fails the whole batch. A45 response lists affected ids, not models: re-query for the record. Through-relations can be read, never46 mutated; chain through the intermediate relation. Constrain relation writes with the required and47 prohibited-on-create/update helpers rather than ad hoc validation.487. **Actions for writes, instructions for reads.** Do not write a custom controller method for a use case49 the package models. An action declares how it is targeted: standalone (no models), classic (whatever the50 search resolves, **every model if search is omitted**), or targeted (explicit ids, required, capped, ids the51 caller cannot see are skipped). Give a destructive or bulk action the targeted form so omitting the52 argument is a validation error (422), not a mass update, and lower the id cap (`$maxResources`, default53 1000) when the blast radius should be smaller. Standalone and targeted are mutually exclusive and combining them throws. An action's field54 payload is a list of name and value pairs, not an object. A queued action dispatches one job per chunk of models (100 by default).558. **Includes are not nested.** An include takes filters, sorts, scopes, limit and selects but not another56 include; go deeper with one include per level and register the chained relation on the intermediate57 resource. An include alias must be an identifier, unique, and not collide with a field, relation or the58 gates key. The shipped guidance is inconsistent here (it also speaks of a "nested include" for dotted59 relation paths): check the installed version before relying on dotted paths or aliases on them.609. **A custom response class can undo the whitelist.** Mapping from the model directly bypasses field61 shaping and authorisation. Use it only to reshape output, reading through the same allowed fields.6210. **Soft-delete routes are opt-in at the route** even when the model uses soft deletes.6311. **Every request is JSON.** The package refuses a request without the JSON accept header. Live form64 validation uses the precognition header when enabled in configuration, which is off by default; a valid65 precognitive request answers 204 and an invalid one 422 (`skills/laravel-precognitive-request-scoping`).6612. **Document with the existing path.** The package integrates with an OpenAPI generator extension; the67 built-in Swagger path is being superseded, so no new customisation there for new work.6813. **The free-text `text` search key needs a Scout-searchable model.** The shipped guidance says the key requires69 a model that uses the searchable trait; check the model before exposing a text search.7071## Output / checkpoint72No exposed model without a full policy, no route for a package-managed model outside `Rest::resource`, no73bulk action that can run unscoped, and no field exposed that is not listed on purpose. Checked at `gate` (7)74and `review` (8).7576## Guardrails77No comments in the code produced. New and changed code only (`skills/code-baseline` §0). A genuine defect in78the package goes to its tracker with a reproduction, not into an app-local shim79(`skills/code-baseline` §7 on customising a third party).8081## Origin82Rewritten from the `laravel-rest-api` skill file shipped inside `lomkit/laravel-rest-api` itself (MIT, LICENSE83read 2026-10-20, default branch pushed 2026-10-13; requirements from its `composer.json`): declaration whitelist,84hook layers, policy and gate model (including the five-minute authorisation cache), mutation all-or-nothing and85id-only responses, action targeting states, id cap and chunk size, include and alias rules, soft-delete opt-in,86precognition and JSON header, OpenAPI path, the custom-response warning and the Scout `text` key. Every step87was re-matched against that file on 2026-10-20. Not confirmed elsewhere: the documentation site88(`laravel-rest-api.lomkit.com`) was opened but the pages on includes returned 404, so the include rules rest on89that one file, which contradicts itself on dotted paths. Steps 1 (extend rather than parallel, and the advice90not to push the package onto a project without it) and 3's reference to tenant scoping are our own guidance.91Mechanisms only, rewritten in our words.9293Independent verification 2026-10-21: 16 checked (shipped guidance file plus package source and config), 16 matched, 0 corrected, 0 unverified.