Every two weeks I send out a newsletter containing lots of interesting stuff for the modern PHP developer. You can expect quick tips, links to interesting tutorials, opinions and packages. Want to learn the cool stuff? Then sign up now!

Pushing polymorphism to the database

After giving excellent talks at both Laracons,  contributing to Laravel’s new ACL, putting out an interesting Full Stack Radio episode with Wes Bos,  Adam Wathan today published a new screencast. He is now officially on a roll.

After my presentation at Laracon this year, a lot of people asked me how I’d take that same polymorphic approach when the objects would have to be retrieved from the database.

This screencast covers how I’d approach implementing the same idea in a real Laravel application with Eloquent, by using polymorphic relationships and delegation to accomplish the same thing without having to resort to any nasty conditionals.



Freek Van der Herten is a partner and developer at Spatie, an Antwerp based company that specializes in creating web apps with Laravel. After hours he writes about modern PHP and Laravel on this blog. When not coding he’s probably rehearsing with his kraut rock band. He loves waffles and butterflies.