I already created a column username and fill it in the users table that was used with the laravel 5 built in login scaffolding and what I'm trying to do is to use username instead of the default email so I tweak the code that I found in laravel\vendor\compiled.php with the following (refer below)
this default code
public function postLogin(Request $request)
{
$this->validate($request, array('email' => 'required|email', 'password' => 'required'));
$credentials = $request->only('email', 'password');
if ($this->auth->attempt($credentials, $request->has('remember'))) {
return redirect()->intended($this->redirectPath());
}
return redirect($this->loginPath())->withInput($request->only('email', 'remember'))->withErrors(array('email' => $this->getFailedLoginMessage()));
}
to
public function postLogin(Request $request)
{
$this->validate($request, array('email' => 'required', 'password' => 'required'));
if ($this->auth->attempt(['username' => $request->input('email'), 'password' => $request->input('password'), $request->has('remember')])) {
return redirect()->intended($this->redirectPath());
}
return redirect($this->loginPath())->withInput($request->only('email', 'remember'))->withErrors(array('email' => $this->getFailedLoginMessage()));
}
but it give me an error saying
QueryException in Connection.php line 620: SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'where clause' (SQL: select * from
dodong_users
whereusername
= [email protected] and0
= 0 limit 1)
any help, suggestion, recommendation, clues, ideas to fix this so that I could login with username instead of email would be greatly appreciated. Thank you!
Change this:
if ($this->auth->attempt(['username' => $request->input('email'), 'password' => $request->input('password'), $request->has('remember')])) {
To this:
if ($this->auth->attempt(['username' => $request->input('email'), 'password' => $request->input('password')], $request->has('remember'))) {
Looks like you just put $request->has('remember')
in the wrong place. It was looking for a column called 0
because you passed the value of $request->has('remember')
as part of the attempt()
data.
To use an example from the documentation, you were doing this:
if (Auth::attempt(['email' => $email, 'password' => $password, $remember]))
{
// The user is being remembered...
}
When you should have been doing this:
if (Auth::attempt(['email' => $email, 'password' => $password], $remember))
{
// The user is being remembered...
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments