Applying a static filter to the query with with([....])
#499
Replies: 1 comment 1 reply
-
I've done some digging into the When you specify your own Specifying an laravel-query-builder/src/Includes/IncludedRelationship.php Lines 10 to 31 in 810be49 This could be fixed by checking for existing eager-load-entries and chaining the constraint closures within the For the time being you could apply this logic in your code like so: $query = QueryBuilder::for(PropertyEnquiry::class)
->allowedFilters('property_id')
->allowedSorts('property_id', 'start_date', 'end_date')
->allowedIncludes('property', 'property.images');
if (array_key_exists('property', $query->getEagerLoads())) {
$query->with(["property" => function ($q) {
$q->where('property.user_id', auth()->user()->id);
}]);
}
$enquiries = $query->get(); |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello there,
I'm not sure if I am missing something obvious here, but i want to utilise the power for of the query builder but in one instance apply a static filter to the query.
The
PropertyEnquiry
collection has a relation toProperty
class (belongsTo) the property has auser_id
I only want to return enquiries for properties that belong to the authenticated user :It would appear that the
with
gets ignored all together from the query builder and i get all enquires regardless of property owner.Any assistance would be appreciated.
Beta Was this translation helpful? Give feedback.
All reactions