1 | <?php |
||
2 | |||
3 | namespace Turahe\Master\Models; |
||
4 | |||
5 | use Illuminate\Database\Eloquent\Model as BaseModel; |
||
6 | use Turahe\Master\Traits\AutoFilter; |
||
7 | use Turahe\Master\Traits\AutoSort; |
||
8 | |||
9 | /** |
||
10 | * Class Model. |
||
11 | */ |
||
12 | abstract class Model extends BaseModel |
||
13 | { |
||
14 | use AutoFilter; |
||
15 | use AutoSort; |
||
16 | /** |
||
17 | * @var string |
||
18 | */ |
||
19 | protected $keyType = 'string'; |
||
20 | |||
21 | /** |
||
22 | * @var string[] |
||
23 | */ |
||
24 | protected $searchableColumns = ['id', 'name']; |
||
25 | |||
26 | /** |
||
27 | * Model constructor. |
||
28 | * |
||
29 | * @param array $attributes |
||
30 | */ |
||
31 | public function __construct(array $attributes = []) |
||
32 | { |
||
33 | parent::__construct($attributes); |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * @param $query |
||
38 | * @param $keyword |
||
39 | */ |
||
40 | public function scopeSearch($query, $keyword) |
||
41 | { |
||
42 | if ($keyword && $this->searchableColumns) { |
||
0 ignored issues
–
show
|
|||
43 | $query->whereLike($this->searchableColumns, $keyword); |
||
44 | } |
||
45 | } |
||
46 | } |
||
47 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.