If you go into an error blade file for example 403.blade
, you will see it uses construction like:
@extends('errors::layout')
I would like to use the same construction or at least understand how it works.
so I'm trying from a controller
return view('role::account.list');
and getting exception
No hint path defined for [role].
I knew it was not defined, but how can I define it?
Thank you.
The easiest way is to use a ServiceProvider and a loadViewsFrom
call:
https://laravel.com/docs/5.6/packages#views
/**
* Perform post-registration booting of services.
*
* @return void
*/
public function boot()
{
$this->loadViewsFrom(__DIR__.'/path/to/views', 'courier');
}
Will allow you to use view namespace courier:
Route::get('admin', function () {
return view('courier::admin');
});
You can also use the logic that is running behind the scenes, by using the View factory which uses the FileViewFinder:
app('view')->addNamespace('role', resource_path('views/role'));
There are more methods available either via the Factory of via the FileViewFinder, you can retrieve the finder like this:
app('view')->getFinder();
Add hint path like so:
app('view')->addNamespace('role', config('view.paths')[0].'/roles/visitor');
you can do it in a controller or Middleware.
And If you want to change it later just do this:
app('view')->replaceNamespace('role', resource_path('views') . Auth::user()->role->view_path);
Yes it is ridiculous that the error says "hint path" and a function named "addNamespace". And it is upsetting that this is NOT a part of documentation.
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