Posts Learn Components Snippets Categories Tags Tools About
/

How to Provide Fallback Views in Laravel

Learn how to return multiple views in Laravel controller to provide a fallback view when one or more views is not available

Created on Aug 17, 2021

219 views

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.

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

Load comments for How to Provide Fallback Views in Laravel

)