我有一個包含2個用戶類型的管理員和客戶。在我的用戶表中,我有一個名爲「is_admin」的布爾列。當管理員登錄時,他們應該有權訪問一組資源;當用戶登錄時,他們應該可以訪問另一組資源。Laravel - 按用戶類型合併路線
我有一種感覺,我需要使用中間件或策略,但在網上找不到任何好的示例。
任何幫助將不勝感激。
這是代碼從我web.php routes文件
Auth::routes();
Route::group(['middleware' => ['auth']], function() {
Route::get('/', '[email protected]')->name('dashboard');
Route::resource('stock-types', 'StockTypeController');
Route::resource('stock-items', 'StockItemController');
Route::resource('companies', 'CompanyController');
Route::resource('addresses', 'AddressController');
Route::resource('contacts', 'ContactController');
Route::resource('deliveries', 'DeliveryController');
Route::resource('settings', 'SettingController', ['only' => [
'index', 'update',
]]);
Route::resource('users', 'UserController');
});
您需要添加一些代碼,以便我們可以幫助你。 – Troyer
我用我的web.php路徑文件中的代碼更新了我的問題。股票項目資源是用戶可以訪問的資源項目資源,其他資源是針對管理員的。 – sgspragg
'is_admin'是一種自定義的方式。是的,這是可能的,但你必須自己管理一切。 Laravel的方式是使用具有角色和權限的標準ACL方法:http://itsolutionstuff.com/post/laravel-52-user-acl-roles-and-permissions-with-middleware-using-entrust-from- scratch-tutorialexample.html – Axalix