Repository navigation
A minor release of 3.x: extensions, search engine lists, search totals and stricter engine searches. Upgrade with composer update lomkit/laravel-rest-api, then read the 3.6 section of the upgrade guide, starting with its "check these first" list.
Check these first
3.6 removes two public methods, removes the French lines and changes seven behaviours. The upgrade guide details each one.
- Removed:
ActionTransaction::aroundRun()andActionTransaction::handle(). - Removed: the French lines. The package ships its client messages in English only. To keep French, publish the lines before upgrading with
php artisan vendor:publish --tag=rest-lang, delete the publishedencopy, and add the 9 keys new in 3.6, all invalidation.- With a
fallback_localeother thanen, a missing line shows the key itself.
- With a
- Typesense:
typesenseSearchParameters()may no longer return a parameter that the package sends itself;sortable()andtieBreaker()refuseid;- every search sends
filter_curated_hits: true.
- Algolia: every search sends
enableRules: false. search.sourceis a reserved key of the search body.- A search text without a letter or digit (
*,%,_) matches no row. A blank text still returns the list. - A value refused by the engine inside an instruction answers 422 under
search.instructions.Ninstead of a 500.
Extensions
One class adds behaviour to every resource. It declares its name() and implements one or more kinds:
final class QuotaExtension extends Extension implements GuardsWrites
{
public static function name(): string
{
return 'quota';
}
public function guardWrite(WriteGuardContext $context): void
{
$context->refuse('The monthly quota is reached.', 429);
}
}- Registering and disabling: list the classes in
rest.extensions, or callRest::registerExtension()from a package. Disable one inrest.disabled_extensions. - The kinds:
- queries:
RestrictsQueries,AugmentsQueries,NarrowsLimits,DeclaresInstructions; - search engines:
RestrictsEngineQueries,DeclaresIndexAttributes,ProvidesEngineProfiles; - authorization: prepared and versioned row checks, cache context, gates,
NarrowsFields; - routes and writes:
AddsRouteMiddleware,GuardsWrites,ObservesWrites,ObservesReads; - responses and checks:
AddsSearchMeta,AddsDetailsMeta,DocumentsExtension,ChecksResources.
- queries:
rest:checklists every extension and checks each one.
Search engines
- Lists on the engine, on request.
ScoutEngine::servesLists()lets a list run on the engine when the body sends"source": "engine". A list sent withoutsourcestays the normal SQL search.- Engine lists have a stable descending order, and
tieBreaker()names the attribute that settles ties. - Pages trust the engine and report
droppedandtotal_capped.
- Engine lists have a stable descending order, and
ScoutEngine::indexAttributes()declares server-only index attributes, string lists included, for the perimeter, the restrictions and the instructions.- Groups.
whereAny()groups conditions for extensions and instructions. Engine searches accept"type": "or"andnestedfilters on Typesense, Meilisearch, Turbopuffer and the Scout drivers. A repeatedwhereIn()on a string list means AND. - Long Typesense searches above 3,500 characters go through
/multi_searchautomatically. - Curated and promoted hits stay inside the filter on Typesense and Algolia.
lazy()now reads engine searches: a text, or"source": "engine". The keys are read at the call, and the call throws before streaming in two cases:EngineWindowException, beyond the engine window;EngineResultsChangedException, when the results change while the keys are read.
Search totals
A search can ask for totals over every matching row, returned in a root totals key next to total:
{"search": {"filters": [{"field": "client_id", "value": 42}],
"totals": {"measures": [{"type": "sum", "field": "amount"}], "groups": [{"field": "status"}]}}}"total": 143,
"totals": {"exact": true, "all": {"count": 143, "sum_amount": 187340.5},
"groups": [{"field": "status", "buckets": [{"value": "paid", "count": 96}, {"value": "invoiced", "count": 31}, {"value": "pending", "count": 16}],
"other": {"count": 0}, "truncated": false}]}- Declaring what may be totalled:
groupable()andmeasurable()on fields, andScoutEngine::groupable()/measurable()for engines. - Measures:
sum,avg,min,max. - Backends: SQL, Typesense, Meilisearch, Algolia, Turbopuffer and the Scout drivers, with one request shape for all of them.
- Exactness: a figure is never shown as exact unless it is.
- A group cut at its limit says
truncated, andΣ buckets + other = all.count = total. - An engine that cannot count exactly refuses, with a 422 or an
EngineSearchException.
- A group cut at its limit says
- Decimals: measures on engines that store decimals with limited precision are rounded to the model's
decimal:Ncast.
Other changes
- Search texts without a letter or digit match nothing.
ResolvedText::matchesNothing()andTextQuery::termless()tell app code. - The CI runs the Algolia integration against a live application.
Documentation: https://laravel-rest-api.lomkit.com