I am creating a multi-domain Laravel app, so my view files are in separate folders per domain. For example, the following:
return view('pages/' . $_SERVER['SERVER_NAME'] . '/public/home', []);
should load a view under
pages/domain.com/public/home.blade.php
but instead it attempts to load
pages/domain/co/public/home.blade.php
because of the dot notation.
How do I get around this?
You'd need to add a view namespace to set up hints for a particular folder if there're dots in the name.
$domain = 'domain.com';
View::addNamespace($domain, config('view.paths')[0]."/{$domain}/");
Route::get('example', function() use ($domain) {
return view("{$domain}::home");
});
You could use base_path('resources/views')
instead of in the example above config('view.paths')[0]
which is probably a bit more sensible in case someone reorders or changes the value of config('view.paths')
Maybe you could replace the dot with underscore:
$domain = str_replace('.', '_', $_SERVER['SERVER_NAME']);
return view('pages/' . $domain . '/public/home');
and load the view under:
pages/domain_com/public/home.blade.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With