Friend, I believe what you are looking for is "namespaces" in views.
I'll show you two ways (and there are probably still other ways).
Option 1 :
app / Providers / AppServiceProvider.php
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
$this->app['view']->addNamespace('admin', base_path() . '/resources/views/admin');
}
route / web.php
Route::get('/admin', function () {
return view('admin::index');
});
And having the following views structure:
resources/views/admin/index.blade.php
resources/views/admin/partials/hello.blade.php
resources / views / admin / index.blade.php
@include('admin::partials/hello')
resources / views / admin / partials / hello.blade.php
hello from admin
When you access the url "/ admin ", the browser should display the message " hello from admin ".
Option 2 , add the namespace dynamically:
route / web.php
Route::get('/modulo1', function () {
app('view')->addNamespace('modulo', base_path() . '/resources/views/modulo1');
return view('modulo::index');
});
Route::get('/modulo2', function () {
app('view')->addNamespace('modulo', base_path() . '/resources/views/modulo2');
return view('modulo::index');
});
And having the following views structure:
resources/views/modulo1/index.blade.php
resources/views/modulo1/partials/hello.blade.php
resources/views/modulo2/index.blade.php
resources/views/modulo2/partials/hello.blade.php
resources / views / modulo1 / index.blade.php
@include('modulo::partials/hello')
resources / views / modulo1 / partials / hello.blade.php
hello from modulo1
resources / views / modulo2 / index.blade.php
@include('modulo::partials/hello')
resources / views / modulo2 / partials / hello.blade.php
hello from modulo2
When you access the url " / module1 " and " / module2 ", the browser should display its "hello from modulo1" and " hello from modulo2 ".
I created a very simple repository with the test files: example-using-vies-namespaces-laravel
Laravel provides a hook that fires when a view is repackaged: Laravel: View Composers
You can use this view composer to dynamically set the namespace for example, it's just a matter of using creativity.
I did not try but, I think I could still add these namespaces on the routes, or even through middlewares. I've used something like that once, and on my system I've created a ViewServiceProvider and solved it there. It's a question of seeing what gets better on your system, use the same creativity.
I hope it helps.