Support the ongoing development of Laravel.io →
Views Blade Installation
Last updated 2 years ago.
0

Solved!!

There are two ways of adding new paths for views in Laravel:

  1. By using addLocation:

view()->addLocation('/modules/XXXXModule/core/views'); view()->addLocation('/modules/YYYYModule/core/views'); The above will work but if you have a list.blade.php view in each of the folders, if you use this:

return view('list'); it will always return the one it finds in the location registered first, which in this case would be for XXXXModule. So while it works it has its drawbacks for your modular structure.

  1. By using addNamespace:

view()->addNamespace('XXXXModule', '/modules/XXXXModule/core/views'); view()->addNamespace('YYYYModule', '/modules/YYYYModule/core/views'); The above will register each path in a different namespace, so if you have two view files with the same name (i.e. list.blade.php) but are part of two different modules you can access them as following:

// for XXXXModule return view('XXXXModule::list');

// for YYYYModule return view('YYYYModule::list'); This way you have no more conflicts of location.

0

Also on your service provider boot method you can do this;

$this->loadViewsFrom(['path1', 'path2'], 'namespace');

0

Sign in to participate in this thread!

Eventy

Your banner here too?

lithiumbj lithiumbj Joined 26 Oct 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.