我想在我的 Laravel 项目中进行多重身份验证.
I want to make multiple authentication in my laravel project.
我在 auth.php 文件中创建了新的守卫admin",但我不知道如何在我的 authcontroller 中设置新创建的守卫.
I create new guard "admin" in my auth.php file but I don't know how to set new created guard in my authcontroller.
它总是使用我的 auth.php 中的默认"设置:
It always use "defaults" settings from my auth.php:
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
1) 如果您希望在整个应用程序中使用新创建的 admin 保护,您可以更改 defaults<中的值/strong> 的配置文件.
1) If you wish to use newly created admin guard throughout the application, you can change the value in defaults of config file.
2) 如果只有 AuthController 使用 Laravel 内置的 Auth 系统,你可以在 AuthController.php 和 PasswordController.php 中添加这一行 :
2) If it is only about AuthController that uses Laravel's in built Auth system, you can add this line in the AuthController.php and PasswordController.php :
protected $guard = 'admin';
Ref - 检查 Guard 自定义 此处
3) 如果您希望为任何 Auth 相关任务设置一个非默认值的守卫,您可以像这样手动指定:
3) If you wish to you a guard other than default one for any Auth related task, you can specify it manually like this :
// 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
}
参考 - https://laravel.com/docs/5.2/authentication
这篇关于如何在 Laravel 中为 auth 控制器设置新的保护的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
在 Laravel 集合对象中添加新元素add new element in laravel collection object(在 Laravel 集合对象中添加新元素)
在 Laravel 5 中创建编辑模式Creating an edit modal in Laravel 5(在 Laravel 5 中创建编辑模式)
用于集合的 Laravel 5.5 API 资源(独立数据)Laravel 5.5 API resources for collections (standalone data)(用于集合的 Laravel 5.5 API 资源(独立数据))
在 php Laravel 5 中创建自定义辅助函数的最佳实践What is the best practice to create a custom helper function in php Laravel 5?(在 php Laravel 5 中创建自定义辅助函数的最佳实践是什么
没有“Access-Control-Allow-Origin"标头 - LaravelNo #39;Access-Control-Allow-Origin#39; header - Laravel(没有“Access-Control-Allow-Origin标头 - Laravel)
Laravel Passport Route 重定向到登录页面Laravel Passport Route redirects to login page(Laravel Passport Route 重定向到登录页面)