Passed
Push — master ( 522ba7...dac3f8 )
by Andrey
13:44
created

BaseModel::scopeSearchBy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 5
ccs 0
cts 0
cp 0
crap 2
rs 10
1
<?php
2
3
namespace Helldar\Roles\Models;
4
5
use Helldar\Roles\Facades\Config;
6
use Helldar\Roles\Traits\Searchable;
7
use Helldar\Roles\Traits\SetAttribute;
8
use Illuminate\Database\Eloquent\Builder;
9
use Illuminate\Database\Eloquent\Model;
10
11
/**
12
 * @property int $id
13
 * @property string $name
14
 *
15
 * @method static \Illuminate\Database\Eloquent\Model|self create(array $values)
16
 * @method static \Illuminate\Database\Eloquent\Builder|self searchBy(string $value)
17
 */
18
abstract class BaseModel extends Model
19
{
20
    use SetAttribute;
21
    use Searchable;
22
23
    public $timestamps = false;
24
25 42
    protected $fillable = ['name'];
26
27 42
    public function __construct(array $attributes = [])
28 42
    {
29
        $this->setConnection(
30
            Config::connection()
31 42
        );
32 42
33
        parent::__construct($attributes);
34
    }
35
36
    protected function scopeSearchBy(Builder $builder, string $value)
37
    {
38
        return $builder
39
            ->where('id', $value)
40
            ->orWhere('name', $value);
41
    }
42
}
43