Laravel 9:更改用于身份验证和登录的表和字段

问题描述 投票:0回答:2

我已将用于身份验证的表和 Laravel Breeze 字段更改为一些自定义字段。它看起来不错,但是在

AuthenticatedSessionController.php
中,当它执行时我得到
Auth::Check() == true
return redirect()->intended(RouteServiceProvider::HOME);
,我被重定向到登录页面,没有任何错误消息。

AuthenticatedSessionController.php

public function store(LoginRequest $request)
{
    $request->authenticate();

    $request->session()->regenerate();
    //Auth::Check() == true here I get true.

    return redirect()->intended(RouteServiceProvider::HOME);
}

我只修改了

$user->getAuthPassword
以返回密码的新字段和
protected $table
中的
fillables
变量(和
user model
)以显示新表。

php laravel authentication laravel-9 laravel-breeze
2个回答
0
投票

如果您去

LoginRequest
课程,您会看到
authenticate()

你看到这部分了:

if (! Auth::attempt($this->only('username', 'password'), $this->boolean('remember'))) {
    RateLimiter::hit($this->throttleKey());

    throw ValidationException::withMessages([
        'email' => __('auth.failed'),
    ]);
}

改变这个:

$this->only('username', 'password')

对此:

[
    'name' => $this->input('username'),
    'password' => $this->input('password'),
]

实际上,您只需输入数据库列作为数组键,并将请求输入作为值。


0
投票

如果您的自定义表主键不是“id”,您是否在 model.php 文件中指定了受保护的 $primaryKey?就我而言,当我指定 $primaryKey 时,它会将我重定向到仪表板。

© www.soinside.com 2019 - 2024. All rights reserved.