| @@ 8-26 (lines=19) @@ | ||
| 5 | use Illuminate\Database\Eloquent\Relations\MorphMany; |
|
| 6 | use Illuminate\Database\Eloquent\Relations\MorphToMany; |
|
| 7 | ||
| 8 | class Post extends Model |
|
| 9 | { |
|
| 10 | use Cachable; |
|
| 11 | ||
| 12 | protected $fillable = [ |
|
| 13 | "title", |
|
| 14 | "body", |
|
| 15 | ]; |
|
| 16 | ||
| 17 | public function comments() : MorphMany |
|
| 18 | { |
|
| 19 | return $this->morphMany(Comment::class, "commentable"); |
|
| 20 | } |
|
| 21 | ||
| 22 | public function tags() : MorphToMany |
|
| 23 | { |
|
| 24 | return $this->morphToMany(Tag::class, "taggable"); |
|
| 25 | } |
|
| 26 | } |
|
| 27 | ||
| @@ 7-24 (lines=18) @@ | ||
| 4 | use Illuminate\Database\Eloquent\Relations\MorphMany; |
|
| 5 | use Illuminate\Database\Eloquent\Relations\MorphToMany; |
|
| 6 | ||
| 7 | class UncachedPost extends Model |
|
| 8 | { |
|
| 9 | protected $fillable = [ |
|
| 10 | "title", |
|
| 11 | "body", |
|
| 12 | ]; |
|
| 13 | protected $table = "posts"; |
|
| 14 | ||
| 15 | public function comments() : MorphMany |
|
| 16 | { |
|
| 17 | return $this->morphMany(UncachedComment::class, "commentable"); |
|
| 18 | } |
|
| 19 | ||
| 20 | public function tags() : MorphToMany |
|
| 21 | { |
|
| 22 | return $this->morphToMany(Tag::class, "taggable"); |
|
| 23 | } |
|
| 24 | } |
|
| 25 | ||