1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Laravel ログイン条件カスタマイズでor条件

Last updated at Posted at 2021-02-11

App\Http\Controllers\Auth\LoginController


下記を加えると(オーバーライド)、例えばroleが1の場合とログイン条件を変更できますが

App\Http\Controllers\Auth\LoginController
    protected function credentials(Request $request)
    {
        return array_merge( 
            $request->only($this->username(), 'password'), // 標準の条件
            [ 'role' => 1 ] // 追加条件
        );
    }

これをroleを3または4みたいにしたい場合は配列にするだけです

App\Http\Controllers\Auth\LoginController
    protected function credentials(Request $request)
    {
        return array_merge( 
            $request->only($this->username(), 'password'), // 標準の条件
            [ 'role' => [3,4] ] // 追加条件
        );
    }
1
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?