Hello their i am using laravel 5.1 and i have problem with redirecting the path of user. i have a roles table, a users table and role_user table means pivot table. Every thing is fine nice but i failed to redirect the page of different user. . This is my User Model. I have not created any middleware
public function roles()
{
return $this->belongsToMany('my\role');
}
public function hasRole($role)
{
if (is_string($role)){
return $this->roles->contains('name', $role);
}
return !! $role->intersect($this->roles)->count();
}
This is my AuthController:
public function redirectPath()
{
// Logic that determines where to send the user
if (\Auth::user()->hasRole('GlobalAdmin', 'SuperAdmin', 'CompanyAdmin', 'GroupAdmin')) {
return '/adminpanel';
}
return '/dashboard';
}
}
When i login as role globleadmin iIt works fine and redirect to adminpanel but when i login as another assigned role it redirect to dashboard. I did'n get it perhaps i passed arguments in authcontriller as: if (\Auth::user()->hasRole('GlobalAdmin', 'SuperAdmin', 'CompanyAdmin', 'GroupAdmin')) is incorrect. Please help me.
This is my route:
Route::get('/adminpanel', 'Admin\adminscontroller@index');
And This is my adminscontroller:
class adminscontroller extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return view('Admin.AdminPanel');
}
}
Thanks in advance.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire