【发布时间】:2020-01-07 18:17:19
【问题描述】:
如前所述,我想使用不同的表(客户端)进行身份验证。
我已经编辑了一些代码,但是我仍然无法使用auth方法。
我尝试了太多变种,但在用户注册后仍然无法使用身份验证登录。
config/auth.php
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'client' => [
'driver' => 'session',
'provider' => 'clients',
]
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
'clients' => [
'driver' => 'eloquent',
'model' => App\Client::class,
],
客户端模式文件。
class Client extends Authenticatable
{
protected $guard = 'client';
public $timestamps = true;
protected $fillable = [
'email',
'password',
'fullname',
];
protected $hidden = [
'password', 'remember_token',
];
}
客户端迁移文件。
Schema::create('clients', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('email')->unique();
$table->string('password');
$table->string('fullname');
$table->rememberToken();
$table->timestamps();
});
控制器
public function showRegister()
{
return view('pages.register');
}
public function doRegister(ClientRequest $request)
{
$validated = $request->validated();
$request->merge(['created_at' => Carbon::now()]);
$request->merge(['password' => Hash::make($request->password) ]);
$add = Client::create($validated);
auth('client')->attempt($add);
return redirect('my_profile')->with('success', 'success');
}
提交注册表后出现此错误。
Symfony\Component\Debug\Exception\FatalThrowableError
Argument 1 passed to Illuminate\Auth\SessionGuard::attempt() must be of the type array, object given, called in C:\wamp64\www\laravel\app\Http\Controllers\HomepageController.php on line 117
当我像这样更改我的尝试代码时,它返回 null。
auth('client')->attempt([
'email'=> $request->email,
'password'=> $request->password
]);
【问题讨论】:
-
您的用户是否在表格中成功注册?
-
是的,先生,没有问题。