Open phoenixz0024 opened 6 years ago
Hi @phoenixz0024 Are you getting any specific error?
Thanks for answering, no I am not getting an error. It is just redirecting to ('/') so I assume hasRole() returns false; I've tested this and hasRole() returns true when i have either coach or the admin role.
Any other suggestions? I am using laravel 5.2
have you included
'role' => \Zizaco\Entrust\Middleware\EntrustRole::class,
in your kernel.php
I've added everything according to the setup
'role' => \Zizaco\Entrust\Middleware\EntrustRole::class,
'permission' => \Zizaco\Entrust\Middleware\EntrustPermission::class,
'ability' => \Zizaco\Entrust\Middleware\EntrustAbility::class,
try putting dd($roles);
in your middleware and let me know what u are getting there.
dd($roles); in EntrustRole class outputs the following; "coach|manager"
try dd($this->auth->guest() , $request->user()->hasRole(explode('|', $roles))
in middleware
Output:
false true
That means everything is working according to the response you are getting.Issue is something else. You are not getting redirected to ('/') route from middleware.you can check by putting dd(123) inside if and dd(456) outside if condition you will get 456 .
Ok so according to this, it doesnt go to redirect('/') but its returning the $next($request);. What will be the next step to look for an error.
Do I have to mention the middleware in the __construct method?
Now the only solution is you have to check line by line .So firstly go to the function from your route .And try to print there.If it is getting there or not.
I think I fixed it. In my controller i had this in the __construct()
public function __construct()
{
$this->middleware('auth' );
$this->middleware(['role:coach'] , ['except' => ['index','show']]);
}
This isn't working, but if comment these its working... Could you explain this?
yes you actually don't need this.
Hello,
Ive been using Entrust in my application. Ive done everything according to the installation.
Anyhow;
Route::group(['middleware' => ['role:admin|coach']], function() { // my routes }
Ive been logged in as an user with the role Admin. However I always get redirected to ('/'). Any suggestions?
My middleware handler function
`