| @@ 64-84 (lines=21) @@ | ||
| 61 | $searchFields = $this->searchFields; |
|
| 62 | $searchFields = !empty($searchFields) ? explode(',', $searchFields) : $searchableFields; |
|
| 63 | ||
| 64 | if ($search && $searchableFields) { |
|
| 65 | $model = $model->where(function ($query) use ($requestFields, $searchableFields, $searchFields, $search) { |
|
| 66 | ||
| 67 | $isFirstField = true; |
|
| 68 | ||
| 69 | foreach ($searchFields as $field) { |
|
| 70 | if (!in_array($field, $searchableFields)) { |
|
| 71 | continue; |
|
| 72 | } |
|
| 73 | ||
| 74 | $value = "%{$search}%"; |
|
| 75 | ||
| 76 | if ($isFirstField && !is_null($value)) { |
|
| 77 | $query->where($field, 'like', $value); |
|
| 78 | $isFirstField = false; |
|
| 79 | } elseif (!is_null($value)) { |
|
| 80 | $query->orWhere($field, 'like', $value); |
|
| 81 | } |
|
| 82 | } |
|
| 83 | }); |
|
| 84 | } |
|
| 85 | ||
| 86 | if ($filterableFields) { |
|
| 87 | $model = $model->where(function ($query) use ($requestFields, $filterableFields) { |
|
| @@ 51-71 (lines=21) @@ | ||
| 48 | $searchFields = $this->searchFields; |
|
| 49 | $searchFields = !empty($searchFields) ? explode(',', $searchFields) : $searchableFields; |
|
| 50 | ||
| 51 | if ($search && $searchableFields) { |
|
| 52 | $model = $model->where(function ($query) use ($searchableFields, $searchFields, $search) { |
|
| 53 | ||
| 54 | $isFirstField = true; |
|
| 55 | ||
| 56 | foreach ($searchFields as $field) { |
|
| 57 | if (!in_array($field, $searchableFields)) { |
|
| 58 | continue; |
|
| 59 | } |
|
| 60 | ||
| 61 | $value = "%{$search}%"; |
|
| 62 | ||
| 63 | if ($isFirstField && !is_null($value)) { |
|
| 64 | $query->where($field, 'like', $value); |
|
| 65 | $isFirstField = false; |
|
| 66 | } elseif (!is_null($value)) { |
|
| 67 | $query->orWhere($field, 'like', $value); |
|
| 68 | } |
|
| 69 | } |
|
| 70 | }); |
|
| 71 | } |
|
| 72 | ||
| 73 | return $model; |
|
| 74 | } |
|