Completed
Pull Request — master (#372)
by Mike
31:01 queued 16:07
created

UncachedAuthor::scopeStartsWithA()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php namespace GeneaLabs\LaravelModelCaching\Tests\Fixtures;
2
3
use Illuminate\Database\Eloquent\Builder;
4
use Illuminate\Database\Eloquent\Model;
5
use Illuminate\Database\Eloquent\Relations\HasMany;
6
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
7
use Illuminate\Database\Eloquent\Relations\HasOne;
8
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
9
use Illuminate\Database\Eloquent\SoftDeletes;
10
11
class UncachedAuthor extends Model
12
{
13
    use SoftDeletes;
14
    
15
    protected $casts = [
16
        "finances" => "array",
17
    ];
18
    protected $fillable = [
19
        'name',
20
        'email',
21
        "finances",
22
    ];
23
    protected $table = 'authors';
24
25
    public function books() : HasMany
26
    {
27
        return $this->hasMany(UncachedBook::class, 'author_id', 'id');
28
    }
29
30
    public function getLatestBookAttribute()
31
    {
32
        return $this
33
            ->books()
34
            ->latest("id")
35
            ->first();
36
    }
37
38
    public function printers() : HasManyThrough
39
    {
40
        return $this->hasManyThrough(Printer::class, Book::class, "author_id");
41
    }
42
43
    public function profile() : HasOne
44
    {
45
        return $this->hasOne(UncachedProfile::class, 'author_id', 'id');
46
    }
47
48
    public function scopeStartsWithA(Builder $query) : Builder
49
    {
50
        return $query->where('name', 'LIKE', 'A%');
51
    }
52
53
    public function scopeNameStartsWith(Builder $query, string $startOfName) : Builder
54
    {
55
        return $query->where("name", "LIKE", "{$startOfName}%");
56
    }
57
}
58