Completed
Push — master ( e48405...3cf851 )
by Karl
27s
created

Recruiter::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
crap 1
1
<?php namespace JobApis\JobsToMail\Models;
2
3
use Illuminate\Database\Eloquent\Model;
4
use Illuminate\Support\Facades\DB;
5
use Ramsey\Uuid\Uuid;
6
7
class Recruiter extends Model
8
{
9
    /**
10
     * Indicates that the IDs are not auto-incrementing.
11
     *
12
     * @var bool
13
     */
14
    public $incrementing = false;
15
16
    /**
17
     * The attributes that are mass assignable.
18
     *
19
     * @var array
20
     */
21
    protected $fillable = [
22
        'name',
23
        'url',
24
    ];
25
26
    /**
27
     * Boot function from laravel.
28
     */
29 2
    protected static function boot()
30
    {
31 2
        parent::boot();
32
33 2
        static::creating(function ($model) {
34 1
            $model->{$model->getKeyName()} = Uuid::uuid4();
35 2
        });
36 2
    }
37
38
    /**
39
     * Very simple filter to get recruiting firms by name
40
     *
41
     * @param $query
42
     * @param string $name
43
     *
44
     * @return \Illuminate\Database\Eloquent\Builder
45
     */
46 1
    public function scopeWhereNameLike($query, $name = null)
47
    {
48 1
        $where = "to_tsvector('english', name) @@ plainto_tsquery('english', ?)";
49 1
        return $query->whereRaw($where, [$name]);
50
    }
51
}
52