I have a multiauth laravel 5.2 app, with the fallowing guards defined on config/auth.php
:
...
'admin' => [
'driver' => 'session',
'provider' => 'admin',
],
'user' => [
'driver' => 'session',
'provider' => 'user',
],
...
So, admin
and user
.
The problem resides in the view layer, since this two loggedin guards share some views, ex:
Hello {{Auth::guard('admin')->user()->name}}
In this case the guard is hardcoded into the view to be always admin
(it gives error when loggedin guard is user
), but, to avoid have to do another equal view just for this little change, I would like have it dinamic, something like:
Hello {{Auth::guard(<LOGGEDIN GUARD>)->user()->name}}
PS: I know that this could be achieved getting the corresponding url segment, ex: www.site.com/pt/user/dasboard
which in the case it would be segment 2, but this way the app would lose scalability, since in the future the corresponding segment may not be the same (2 in the example above)
getGuard()
and how it's implemented in Laravel'sauth
area. Think that will get you going in right direction. – MultipedAuth::guard($this->getGuard())
triggersMethod [getGuard] does not exist.
. I guess it's a 5.1 feature, i also checked #35625061 , with same result – Autohypnosisprotected
, you can't use$this
to access it. But you might be able to access with something likeAuth::guard(Auth::getGuard())
but I'm not positive. – Multiped...class 'Illuminate\Auth\SessionGuard' does not have a method 'getGuard'
– Autohypnosis