Did you know about view()->exists() function?

When you load a View from the Controller, there could be a situation when you don't actually know which view to load - the name could be dynamic. For example, you would use different Blade templates for sending emails. There is a neat function to assure your chosen View file actually exists. It goes as simple as this:
if (view()->exists('emails.' . $template))
    // ... sending an email to the customer
I personally would consider this approach a bad practice - you should catch that error in Controller or elsewhere in the logic before actually calling the View. But if for some reason you get to this point - function exists() can be handy. More info about Views - in the official documentation.

No comments yet…

Like our articles?

Become a Premium Member for $129/year or $29/month

Written by