我有两个用户,我有两个角色:普通用户和债务人用户。我想要防止债务人用户访问普通用户仪表板的方法。我也创建了债务人仪表板。下面是我尝试过的方法。如何归档此文件。
这是我的web.php
////// User debtors Authentications ///////////
Route::middleware(['debtors'])->group(function(){//debtors routes will goes here
Route::get('/debtors/home', 'HomeController@kfsdebtors_form');
Route::get('/debtors/kfsdebtors_form', 'HomeController@defaultersdashboard');
Route::get('/debtors/applications_dashboard', 'HomeController@applications_dashboard');
Route::get('/debtors/manage_debt', 'HomeController@manage_debt');
Route::post('/debtors/manage_debt', 'HomeController@transaction');
Route::get('/debtors/manage_debt', 'HomeController@defaulters');
Route::get('/debtors/view_transaction', 'HomeController@view_transaction');
Route::post('/debtors/view_transaction', 'HomeController@view_transaction');
// Route::get('/user/{data}', 'UserController@getData');
// Route::post('/user/{data}', 'UserController@postData');
});
// Route::group(['middleware' => 'debtors'], function () {
// Route::get('/debtors/home/kfsdebtors_form', 'HomeController@kfsdebtors_form');
// Route::get('/debtors/applications_dashboard', 'HomeController@applications_dashboard');
// Route::get('/debtors/manage_debt', 'HomeController@manage_debt');
// });
////// User normal user Authentications ///////////
Route::middleware(['normal_user'])->group(function(){
Route::get('/home', 'HomeController@index');
Route::get('/home', 'HomeController@balance');
});
// Route::group(['middleware' => 'is.admin'], function () {
// Route::get('/user/{data}', 'UserController@getData');
// Route::post('/user/{data}', 'UserController@postData');
// });
Route::get('/register_sawmill', 'Auth\register_sawmill@create')->name('register_sawmill');
Route::post('/register_sawmill', 'Auth\register_sawmill@register');
Route::get('logout', 'Auth\LoginController@logout', function () {
这是我的btruptors.php中间件
public function handle($request, Closure $next)
{
if (Auth::user()->debtor == 1)
{
return $next($request);
}
return redirect()->guest('/debtors/home');
}
}
这是normal_user.php中间件
public function handle($request, Closure $next)
{
// if(Auth::check()) {
// if(Auth::user()->debtor == 0) {
// return $next($request);
// }
// }
// return redirect('/home');
// if(!Auth::check() || Auth::user()->debtor != '0'){
// return redirect()->route('/debtors/home');
// }
// return $next($request);
if(Auth::check()) {
if(Auth::user()->debtor == 0) {
return $next($request);
}
}
return redirect('/debtor/home');
}
```
答案 0 :(得分:0)
我认为您应该更改return redirect('/home');
并重定向到一个简单的页面,例如return redirect('/register_sawmill');
我认为的问题是普通用户中间件会检查用户是否已通过身份验证,如果未通过验证,则应该重定向到中间件未维护的某个页面