Repository navigation
v3.1.0
A minor release of 3.x: relations choose the mutation operations they accept. Upgrade with composer update lomkit/laravel-rest-api, then read the 3.1 section of the upgrade guide.
Relation operations
-
->withoutOperations(MutationOperation ...$operations)withdraws operations from a relation,->onlyOperations(MutationOperation ...$operations)keeps only some, and->onlyOperations()makes the relation read-only:BelongsTo::make('team', TeamResource::class)->withoutOperations(MutationOperation::Detach), BelongsToMany::make('tags', TagResource::class)->onlyOperations(MutationOperation::Attach, MutationOperation::Detach),
-
Validation,
/detailsand the OpenAPI document follow: a withdrawn operation answers422. -
A many-to-many relation that does not accept
detachdoes not accepttoggleeither, and itssyncneeds"without_detaching": true. -
A relation that does not accept
updatedoes not write its related rows throughsync,toggleor nestedrelations(pivot values stay writable).
Required links
- A
detachthat would set a foreign key or morph type that does not accept null answers a422on thekeyof the entry, instead of a database error. rest:resource --generateandrest:quick-startadd->withoutOperations(MutationOperation::Detach)to a relation whose foreign key or morph type does not accept null.rest:checkreports each relation that acceptsdetachwhile its link column does not accept null. It reads the database schema: a missing table is skipped, an unreadable schema is reported.
Check after upgrading
rest:checkis stricter: a resource generated with 3.0 on aNOT NULLforeign key now fails it until the relation withdrawsdetachor the column becomes nullable.- On MySQL without strict mode, a
detachon aNOT NULLforeign key used to write0or''; it now answers422.
Documentation: https://laravel-rest-api.lomkit.com