| Conditions | 4 |
| Paths | 4 |
| Total Lines | 19 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | public function scopeSearch(Builder $builder, string $term = '') |
||
| 10 | { |
||
| 11 | if (! $this->searchable) { |
||
| 12 | throw new Exception('Please define the searchable property . '); |
||
| 13 | } |
||
| 14 | foreach ($this->searchable as $searchable) { |
||
| 15 | if (str_contains($searchable, '.')) { |
||
| 16 | $relation = Str::beforeLast($searchable, '.'); |
||
| 17 | |||
| 18 | $column = Str::afterLast($searchable, '.'); |
||
| 19 | |||
| 20 | $builder->orWhereRelation($relation, $column, 'like', "%$term%"); |
||
| 21 | |||
| 22 | continue; |
||
| 23 | } |
||
| 24 | $builder->orWhere($searchable, 'like', "%$term%"); |
||
| 25 | } |
||
| 26 | |||
| 27 | return $builder; |
||
| 28 | } |
||
| 30 |