Completed
Push — master ( 3f89d7...f790e9 )
by Mike
30:28 queued 29:00
created

Book::author()   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 0
1
<?php namespace GeneaLabs\LaravelModelCaching\Tests\Fixtures;
2
3
use GeneaLabs\LaravelModelCaching\Traits\Cachable;
4
use Illuminate\Database\Eloquent\Builder;
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Eloquent\Relations\BelongsTo;
7
use Illuminate\Database\Eloquent\Relations\MorphMany;
8
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
9
use Illuminate\Database\Eloquent\Relations\MorphOne;
10
11
class Book extends Model
12
{
13
    use Cachable;
14
15
    protected $casts = [
16
        'price' => 'float',
17
    ];
18
    protected $dates = [
19
        'published_at',
20
    ];
21
    protected $fillable = [
22
        "author_id",
23
        'description',
24
        'published_at',
25
        'title',
26
        "publisher_id",
27
        'price',
28
    ];
29
30
    public function author() : BelongsTo
31
    {
32
        return $this->belongsTo(Author::class);
33
    }
34
35
    public function comments() : MorphMany
36
    {
37
        return $this->morphMany(Comment::class, "commentable");
38
    }
39
40
    public function image() : MorphOne
41
    {
42
        return $this->morphOne(Image::class, "imagable");
43
    }
44
45
    public function publisher() : BelongsTo
46
    {
47
        return $this->belongsTo(Publisher::class);
48
    }
49
50
    public function stores() : BelongsToMany
51
    {
52
        return $this->belongsToMany(Store::class);
53
    }
54
55
    public function scopeStartsWith(Builder $query, string $startOfName) : Builder
56
    {
57
        return $query->where("name", "LIKE", "{$startOfName}%");
58
    }
59
}
60