All of us know that Laravel allows us to nest child view easily:
return View::make("myView")->nest("sidebar", "sidebar");
But what if I need the sidebar in my every view. That seems awkward to nest it each time. specially that there are many nested views such as : footer, header, navigation, sidebar.
Is there a way to have a nested view without explicitly declaring it each time?
I don't want to use Blade Engine .
I believe you can attach a view composer to the layout specified in your BaseController
.
Something like:
View::composer('layout', function($view)
{
$view->with('sidebar', 'sidebar');
});
You can put this code on routes.php or create a composers.php in app folder.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.