Skip to main content
Tutorial Free

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

July 10, 2015
1 min read
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.

Enjoyed This Tutorial?

Get access to all premium tutorials, video and text courses, and exclusive Laravel resources. Join our community of 10,000+ developers.

Comments & Discussion

No comments yet…

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.