Source: tighten.com

Encapsulating Polymorphism
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.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners