Laravel 5.5 – Dynamic templates with View::first

Laravel 5.5 is introduced a new feature called dynamic view loading and it makes your controllers simple and more expressive when dealing with dynamic templates. Using This feature we can avoid plain old conditional statements to load the appropriate template for the request.

For example, let’s assume you have different pages and some page have different layout and stylings requirements. Than dynamic view loading is a perfect candidate for this requirement. Let’s see how it will look like

The first() method is going to load first matched template, if the template doesn’t exist,
then it will fallback to second .. and so .. on, you can pass n number of templates to view::first() method.

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

Arjun

I am Arjun from Hyderabad (India). I have been working as a software engineer from last 7+ years, and its my passion to learn new things and implement them as a practice. Aside from work, I likes gardening and spending time with pets.


DMCA.com Protection Status