【发布时间】:2021-10-28 13:47:45
【问题描述】:
我正在使用 Laravel 8,并试图让守卫“移动”。我在网上关注了一些教程,但我不知道为什么这些教程中似乎有效的东西在我的最后不起作用。
我在互联网上搜索,我能找到的只有php artisan config:clear,但它从来没有为我工作过。
这是来自我的auth.php 文件的代码:
<?php
return [
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'mobile'=> [
'driver'=>'session',
'provider'=>'technicians'
],
'api' => [
'driver' => 'sanctum',
'provider' => 'users',
'hash' => false,
]
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\User::class,
],
'technicians' => [
'driver' => 'eloquent',
'model' => App\Models\Technician::class,
]
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
'passwords' => [
'users' => [
'provider' => 'users',
'table' => 'password_resets',
'expire' => 60,
'throttle' => 60,
],
'technicians' => [
'provider' => 'technicians',
'table' => 'password_resets',
'expire' => 60,
'throttle' => 60
]
],
'password_timeout' => 10800,
];
在我的控制器中,我使用这一行进行身份验证,这反过来又给了我错误:
Auth::guard('mobile')->attempt(['email'=>'testmail@test.com',password=>'password']);
【问题讨论】:
-
分享错误,Laravel 到底说了什么?你试过
php artisan cache:clear吗?或者你可以在root-app/bootstrap/cache/*.php删除php文件 -
@MohamedGamalEldin
InvalidArgumentException Auth guard [mobile] is not defined.,这是我遇到的错误 -
您是否在 Technician 模型中扩展了 Authenticatable?
use Illuminate\Foundation\Auth\User as Authenticatable; class Technician extends Authenticatable {
标签: php laravel authentication laravel-8