1)如果您希望在整个应用程序中使用新创建的管理员防护,您可以更改配置文件默认值中的值.
2)如果只是在AuthController中使用Laravel的内置Auth系统,你可以在AuthController.php和PasswordController.php中添加这一行:
protected $guard = 'admin';
参考 – 检查Guard Customization here
3)如果您希望任何Auth相关任务的默认保护,您可以手动指定它:
// For route middleware
Route::get('profile', [
'middleware' => 'auth:admin',
'uses' => 'ProfileController@show'
]);
// For manually logging the user in
if (Auth::guard('admin')->attempt($credentials)) {
// Authenticated...
}
// To login specific user using eloquent model
Auth::guard('admin')->login($user);
// For getting logged in user
Auth::guard('admin')->user();
// To check if user is logged in
if (Auth::guard('admin')->check()) {
// Logged in
}