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