A Pro subscription is required to watch this lesson.

In this Larabit, I'll show you how to refactor a series of confusing PHP conditionals into a simple lookup table. To accomplish this, we'll leverage PHP 8's match expression and its ability to handle non identity checks.

As we work on this refactor, we'll also talk briefly about the strategy pattern, and how to extract a factory method to build up the appropriate object. I think you'll enjoy it!

Refactor ConditionalsPHP 8's Match ExpressionStrategies

Would you like to hear from Laracasts by email occasionally?