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 or questions yet...

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 59 courses (1056 lessons, total 42 h 44 min)
  • 78 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord

Recent Premium Tutorials