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 :)
When i remove 'use AuthenticatesAndRegistersUsers' line, i get a notfound exception:
NotFoundHttpException in Controller.php line 269: Controller method not found.
That's because some methods are used in that trait. You should keep that line and just override the postLogin method.
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-authorization-module-email-to-username
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
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community