0
0

More than 1 year has passed since last update.

Laravel Fortify メールアドレス以外でログインする

Posted at

Laravel Fortify でログイン方法をメールアドレスから別のカラムに変更したい人向け。
簡単2ステップで、終わりです。

①FortifyServiceProviderに追記する

FortifyServiceProviderのbootメソッドに下記の通り、追加

FortifyServiceProvider.php
    public function boot()
    {
        Fortify::authenticateUsing(function (Request $request) {
            $user = User::whereLoginId($request->login_id)->first();

            if ($user &&
                Hash::check($request->password, $staffMember->password)) {
                return $user;
            }
        });
    }

②config/fortify.phpを変更する

'username'というのがどこかにありますので、それを'email'から指定したいカラムに変更します。

config/fortify.php
 //'username' => 'email', // デフォルト
 'username' => 'login_id',

これで完了です。
公式ドキュメントも読んでみてください。
https://laravel.com/docs/9.x/fortify#customizing-user-authentication

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0