Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 395
OPV Avatar asked Oct 19 '25 17:10

OPV


1 Answers

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;
    } 
like image 168
Emtiaz Zahid Avatar answered Oct 21 '25 06:10

Emtiaz Zahid



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!