3

I'm building a modular system in Laravel 5 and the modules views of my system are outside from the /resources/views. They are under /modules/XXXXModule/core/views.

When I use the return view('viewFileHere') it doesn't work (logically) because is looking for the views in the wrong place.

How can I tell Laravel 5 to search for the views in other place (path)?

1 Answer 1

4

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.

2. 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.

Sign up to request clarification or add additional context in comments.

1 Comment

Wonderfull! Thanks you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.