簡體   English   中英

更改 Laravel 中的默認身份驗證字段(電子郵件、密碼)

[英]Change the default Authentification fields (email ,password ) in Laravel

默認情況下,Laravel 使用 email 和密碼字段進行身份驗證,我想更改默認的身份驗證字段並將code_massar、date_naissance字段設置為默認

任何幫助!

   Schema::create('users', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string("code_massar");
            $table->date("date_naissance");
            $table->string('email')->unique();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });

我使用 breez package 作為身份驗證方法!

我在 laravel 中找到了一種方法 5

檢查這篇文章。 它與 ldap 一起使用,但我認為它應該有用https://ldaprecord.com/docs/laravel/v2/auth/database/laravel-breeze/#introduction

Go 驗證您的 LoginController 方法並根據需要修改它

public function authenticate(Request $request)
{
    $credentials = $request->validate([
        'code_massar' => ['required'],
        'date_naissance' => ['required'],
    ]);

    if (Auth::attempt($credentials)) {
        $request->session()->regenerate();

        return redirect()->intended('dashboard');
    }

    return back()->withErrors([
        'code_massar' => 'The provided code_massar do not match our records.',
        'date_naissance' => 'The provided date_naissance do not match our records.',
    ]);
 }

你可以在這里看到更多https://laravel.com/docs/9.x/authentication#authenticating-users

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM