dongnuo4594 2019-03-29 16:54
浏览 55

Laravel - 如果已连接则重定向

I am a young French developer and I am at a dead end about redirections under Laravel.

I have user tables, namely Client(users) and Employes (admin) and I can log on without problem with a login form that sends me to 2 different pages:

 Connected as a client-> mon-compte,
 Logged in as an employe-> gestion-admin.

However, if I am logged in as a client and I change the url mon-compte by gestion-admin, I have access to this page and vice versa ...

So I set guards and middlewares under Laravel that seem to work but that alternately I will say. In my web.php, I have 2 groups:

Route::group([
'middleware' => 'App\Http\Middleware\Employe',
], function () {
    Route::get('/mon-compte', 'ControllerConnexion@accueilClient');
    Route::view('mon-compte', 'pages/mon-compte');
    Route::get('/gestion-admin', 'ControllerConnexion@redirectClient');
});

Route::group([
'middleware' => 'App\Http\Middleware\Client',
], function () {
    Route::get('/gestion-admin', 'ControllerConnexion@accueilEmploye');
    Route::view('gestion-admin', 'pages/gestion-admin');
    Route::get('/mon-compte', 'ControllerConnexion@redirectEmploye');

});

In this order of position of the groups, the access used is blocked if I change the url /gestion-admin by /mon-compte if I connect as a client, I arrive directly on the gestion-page page . If I change the url and want to go to mon-compte, it sends me back to gestion-admin.

By cons, if I reverse the 2 groups of position:

Route::group([
'middleware' => 'App\Http\Middleware\Client',
], function () {
    Route::get('/gestion-admin', 'ControllerConnexion@accueilEmploye');
    Route::view('gestion-admin', 'pages/gestion-admin');
    Route::get('/mon-compte', 'ControllerConnexion@redirectEmploye');

});

Route::group([
'middleware' => 'App\Http\Middleware\Employe',
], function () {
    Route::get('/mon-compte', 'ControllerConnexion@accueilClient');
    Route::view('mon-compte', 'pages/mon-compte');
    Route::get('/gestion-admin', 'ControllerConnexion@redirectClient');
});

I have the opposite effect ....

I admit that I have no solution.

  • 写回答

1条回答 默认 最新

  • doujingqu3030 2019-03-29 22:12
    关注

    Think ' if(auth()->check) ' should be ' if( ! auth()->check ) '

    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)