Skip to content

Commit

Permalink
pass $search to scope and don't search like when the scope is specificed
Browse files Browse the repository at this point in the history
  • Loading branch information
vuthaihoc authored Apr 28, 2023
1 parent 2009e63 commit bc63d2f
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/Http/Controllers/AdvancedRelationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ private function buildersItems(
)
{
if ($scope !== null) {
$scope['parameters'][] = $search;
/** @var Collection|array $model */
$model = $model->{$scope['name']}(...$scope['parameters']);
}
Expand All @@ -88,14 +89,16 @@ private function buildersItems(
return $model->take($chunk)->pluck($append ?? $name, $key);
}

$model = $model->where(function ($query) use ($name, $search, $searchColumns) {
$query->where($name, 'like', '%' . $search . '%');
if ($searchColumns !== null) {
foreach ($searchColumns as $column) {
$query->orWhere($column, 'like', '%' . $search . '%');
if($scope == null){
$model = $model->where(function ($query) use ($name, $search, $searchColumns) {
$query->where($name, 'like', '%' . $search . '%');
if ($searchColumns !== null) {
foreach ($searchColumns as $column) {
$query->orWhere($column, 'like', '%' . $search . '%');
}
}
}
});
});
}

return $model
->limit($chunk)
Expand Down

0 comments on commit bc63d2f

Please sign in to comment.