skip to Main Content

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

2

Answers


  1. 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

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search