Skip to content

Commit

Permalink
Always include unassigned locationables
Browse files Browse the repository at this point in the history
  • Loading branch information
sampoyigi committed Jan 2, 2024
1 parent 4c07e34 commit 1446045
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Traits/LocationAwareWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected function isLocationAware($config)
/**
* Apply location scope where required
*/
protected function locationApplyScope($query)
protected function locationApplyScope($query, $config = [])
{
$model = $query->getModel();
if (!$model instanceof Location && !in_array(Locationable::class, class_uses($model))) {
Expand All @@ -29,8 +29,12 @@ protected function locationApplyScope($query)
return;
}

$model instanceof Location
? $query->whereIn('location_id', $ids)
: $query->whereHasLocation($ids);
if ($model instanceof Location) {
$query->whereIn('location_id', $ids);
} else if (array_get($config, 'locationAware') === 'assignedOnly') {
$query->whereHasLocation($ids);
} else {
$query->whereHasOrDoesntHaveLocation($ids);
}
}
}

0 comments on commit 1446045

Please sign in to comment.