Support the ongoing development of Laravel.io →
Authentication
Last updated 1 year ago.
0

AuthenticatesAndRegistersUsers is a trait in the laravel framework. You should never edit composer imported files, as they will be overwritten on update.

Remove the following line

use AuthenticatesAndRegistersUsers

from the AuthController and create the postLogin method.


public function postLogin(Request $request)
{
     $validation = $this->validate($request, [
            'username' => 'required', 
                        'password' => 'required',
        ]);
     if($validation->fails()){
         return back()->withInput();
     }

  $input = $request->only(['username', 'password']);
        if($this->auth->attempt($input)){
            return redirect()->intended($this->redirectPath());
        }
    return redirect->back()->withInput();
}

Haven't tested the code, but it should work :)

0

When i remove 'use AuthenticatesAndRegistersUsers' line, i get a notfound exception:

NotFoundHttpException in Controller.php line 269: Controller method not found.

0

That's because some methods are used in that trait. You should keep that line and just override the postLogin method.

0

The solution provided above by @moinescumihai does not actually work but

if you add a $username property to the AuthController

protected $username = 'username';

as described in this StackOverflow thread http://stackoverflow.com/questions/28584531/modify-existing-au...

to enable the loginUsername method to use the username property public function loginUsername() { return property_exists($this, 'username') ? $this->username : 'email'; } that will solve the problem, thanks

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.