Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Laravel News:
Dynamic templates in Laravel Blade with View::first
Sep 14, 2017 @ 15:54:11

On the Laravel News site there's a tutorial posted showing you how to use Blade's View::first functionality to dynamically show a template if it exists.

When building dynamic components or pages sometimes we want to display a custom template if it exists or otherwise fall back on a default one.

[...] We can solve this problem with a series of conditionals or by using view()->exists() to check if a custom template exists or not, however, Laravel 5.5 brings us a better and more elegant way.

A screencast of the functionality in action is included as well as a text-only version with code samples showing the previously used "if view exists" check and the refactor to use View::first instead.

This dynamic view loading feature was added to Blade in Laravel v5.5 and is a great way of keeping your controllers simple by avoiding extra conditionals when dealing with dynamic templates.
tagged: dynamic template laravel blade view first refactor laravel55

Link: https://laravel-news.com/viewfirst


Trending Topics: