Hello,
I am starting up a new project using Laravel 5 and Zizaco Entrust for roles.
I have setup everything and would like to know how to redirect a user based on their role to the appropriate route. I.e if say, I have a super admin, once they login they should be redirected to superadmin/dashboard route.
@csuarez yes, I did stick with the middleware, I found out that it was really easy stuff.
@ptgokulrajan basically, I didn't change RedirectIfAuthenticated, I just created a new IsRole middleware, i.e IsAdmin.php with something similar to the below:
<?php namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\RedirectResponse;
class IsAdmin {
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$user = $request->user();
if ($user && $user->isAdmin())
{
return $next($request);
}
return new RedirectResponse(url('/'));
}
}