Home / Snippets / How to Provide Fallback Views in Laravel
How to Provide Fallback Views in Laravel cover

How to Provide Fallback Views in Laravel

236

3 years ago

0 comments

When returning the view file from the controller, you can provide an array of blade views and it will provide a fallback for when one view is not available. To do so you can make use of the "first()" method which accepts an array of blade views as the first parameter and the data to be passed on as the 2nd parameter.
return view()->first(['partials.sidebar-tempate', 'partials.default-template'], $data);
This is very useful when you have a theme system that by default has a default theme and when you provide a new custom view then the system will make use of the custom view instead of the default one.
notion avatar

Alaz

Week-end developer currently experimenting with web, mobile, and all things programming.

Topics:

Frontend

Resource

Average

Average

Support Us

If you like our tutorial, support us by being our Patreon or buy us some coffee ☕️

Welcome to PostSrc V3

PostSrc Dark Logo

You have to login to favorite this