![]() Scope filters allow you to add local scopes to your query by adding filters to the URL. This is where scope filters, callback filters and custom filters come in handy. Sometimes more advanced filtering options are necessary. By passing false as the third parameter to AllowedFilter::exact() or AllowedFilter::partial() this behaviour can be disabled: $addRelationConstraint = false QueryBuilder :: for ( User ::class ) -> join ( 'posts', 'er_id', 'users.id' ) -> allowedFilters ( AllowedFilter :: exact ( 'posts.title', null, $addRelationConstraint)) #Scope filters For example, when using a joined table's value for filtering. In some cases you'll want to disable this behaviour and just pass the raw filter-property value to the query. Under the hood we'll add a whereHas statement for the posts that filters for the given title property as well. This works for exact and partial filters. You can also add filters for a relationship property using the dot-notation: AllowedFilter::exact('posts.title'). ![]() The query builder will automatically map 1, 0, 'true', and 'false' as boolean values and a comma separated list of values as an array: use Spatie\QueryBuilder\AllowedFilter // GET /users?filter=1,2,3,4,5
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |