Requests
Allow requests through your application to send specific parameters like filters, includes, appends, fields, sorts and search.
Last updated
Allow requests through your application to send specific parameters like filters, includes, appends, fields, sorts and search.
Last updated
As a new addition to this package, you can now allow your users to use:
Filters by attributes or local query scopes.
Include model relationships.
Append model accessors ().
Select fields from the database ().
Sort by attributes.
Perform a full-text search (using ).
All of the following being conditionally allowed by you on your controllers, like the following example:
You can allow users to include relationships to the JSON:API response.
You may also allow nested includes like so:
Or using a more specific method like allowIncludes
:
You can allow your users to sort by descendant or ascendant order (or both, which is the default behaviour).
As top uses the direction defined in the config as default you can specify a direction instead, the following are all doing the same but in different directions:
Default sorts can be applied by using the following method:
You can allow your users to filter by a model attribute or its relation's attributes.
By default will use similar (LIKE) but you may change this in the config/apiable.php
file:
You can also specify any method you like:
Scoped filters might be used if you want to filter using Eloquent's query scopes:
And even restrict what they can use for filter on each filter like so:
Same with sorts you can apply default filters whenever a user didn't send any via HTTP query parameters that were allowed:
Allow fields will limit the columns selected by the database query being ran by Laravel.
You can also use models in replace of that first argument (the resource type):
Or directly an array as first argument to append to the main response resource (in this case film):
Same as allowing fields by resource type but this will append Model accessors after the query is done.
You can also use models in replace of that first argument (the resource type):
Or directly an array as first argument to append to the main response resource (in this case film):
You can also perform full-text search with this package with the help of Laravel Scout. So the frontend should send something like yourapi.com/?q=search_query
or yourapi.com/?search=search_query
) to perform a search if allowed by the backend.
If you have a table or a component in the frontend that needs to know about what can be filtered or sorted by, you may want to add this to your JSON:API response:
Then the response payload will look like this:
This feature is only available for proper setup of in your model.