Search code examples
phplaravellaravel-5

How to check additional field during login in Laravel?


How to check additional field during login in Laravel?

Now it works from the box and accepts email and password. How to check additionally status parameter when user log in?

I use this LoginController:

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

class LoginController extends Controller
{
   use AuthenticatesUsers;
}

I tried this in LoginController:

public function authenticate(Request $request)
    {
        $credentials = $request->only('email', 'password');
        $credentials['status'] = 1;

        if (Auth::attempt($credentials)) {
            return redirect()->intended('home');
        }
    }

But Laravel ignores this method authenticate().

if to remove use AuthenticatesUsers; it becomes alive, but then does not work logout, login page.


Solution

  • You can add another field to check login by credentials function

    inside you LoginController add credentials function and append extra field with email, password

    Example:

    public function credentials(Request $request)
        {
            $credentials = $request->only($this->email(), 'password');
            $credentials = array_add($credentials, 'status', '1');
            return $credentials;
        }