Programmers aiming for simple, concise code often work to remove conditionals. Polymorphic relationships are such a pattern—a powerful tool that can help us avoid complicated code paths when we’re dealing with similar related items.
For images attached to a post, we’ll display this one: {$post->name} was posted on {$post->created_at}.
{ - return $this->posts->append($this->videos->toArray()); + return $this->hasMany(Taggable::class); The problem with this approach is taggables doesn’t actually return the tagged things.
We really want to replicate the pattern introduced in the Imageable model by having the taggables relationship return the things that implement that contract.