|
| 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 BookWithUncachedStore 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 | + protected $table = "books"; |
| 30 | + |
| 31 | + public function author() : BelongsTo |
| 32 | + { |
| 33 | + return $this->belongsTo(Author::class); |
| 34 | + } |
| 35 | + |
| 36 | + public function comments() : MorphMany |
| 37 | + { |
| 38 | + return $this->morphMany(Comment::class, "commentable"); |
| 39 | + } |
| 40 | + |
| 41 | + public function image() : MorphOne |
| 42 | + { |
| 43 | + return $this->morphOne(Image::class, "imagable"); |
| 44 | + } |
| 45 | + |
| 46 | + public function publisher() : BelongsTo |
| 47 | + { |
| 48 | + return $this->belongsTo(Publisher::class); |
| 49 | + } |
| 50 | + |
| 51 | + public function stores() : BelongsToMany |
| 52 | + { |
| 53 | + return $this->belongsToMany(Store::class); |
| 54 | + } |
| 55 | + |
| 56 | + public function uncachedStores() : BelongsToMany |
| 57 | + { |
| 58 | + return $this->belongsToMany(UncachedStore::class, "book_store", "book_id", "store_id"); |
| 59 | + } |
| 60 | + |
| 61 | + public function scopeStartsWith(Builder $query, string $startOfName) : Builder |
| 62 | + { |
| 63 | + return $query->where("name", "LIKE", "{$startOfName}%"); |
| 64 | + } |
| 65 | +} |
0 commit comments