Home > Back-end >  Change the default Authentification fields (email ,password ) in Laravel
Change the default Authentification fields (email ,password ) in Laravel

Time:01-11

By default, Laravel uses the email and password fields for authentication , I want to change the default fileds for authentication and set the code_massar , date_naissance fields as default

any help !!

   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();
        });

I use breez package as Authentification Method !

I found one method in laravel 5

CodePudding user response:

Check this post. It's with ldap but it should be usefull i think https://ldaprecord.com/docs/laravel/v2/auth/database/laravel-breeze/#introduction

CodePudding user response:

Go to authenticate method of your LoginController and modify it as your need

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.',
    ]);
 }

you can see more here https://laravel.com/docs/9.x/authentication#authenticating-users

  • Related