Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mspace's avatar

Running database query with user login request data

I want to run a database query with the user login form request data before logging the user in. I have been able to achieve this on my localhost by adding the query to AuthenticateUsers.php in my vendor folder but once I move to my cloud hosting service, the code to i added to my vendor folder in development is not included. I know it is not advisable to make changes to the files in the vendor folder. Please i need help to run database query right before user login (laravel 6)

0 likes
6 replies
jlrdw's avatar

Just put the code in the login controller, you just need to override the trait as needed.

mspace's avatar

please can you explain further

jlrdw's avatar

Can you show your login controller.

mspace's avatar
<?php

namespace App\Http\Controllers\Auth;

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

class LoginController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles authenticating users for the application and
    | redirecting them to your home screen. The controller uses a trait
    | to conveniently provide its functionality to your applications.
    |
    */

    use AuthenticatesUsers;

    /**
     * Where to redirect users after login.
     *
     * @var string
     */
   // protected $redirectTo = '/home';

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }
}
jlrdw's avatar
jlrdw
Best Answer
Level 75

Try adding

    public function login(Request $request)
    {
      //////  HERE GET THE INFO FROM REQUEST AND DO YOUR QUERY/////////
       
       ////  LEAVE BELOW THIS ALONE  //////////////////

     ////   BELOW MAY NOT EVEN BE NEEDED TO WORK  TRY WITHOUT FIRST

       $this->validateLogin($request);

        // If the class is using the ThrottlesLogins trait, we can automatically throttle
        // the login attempts for this application. We'll key this by the username and
        // the IP address of the client making these requests into this application.
        if (method_exists($this, 'hasTooManyLoginAttempts') &&
            $this->hasTooManyLoginAttempts($request)) {
            $this->fireLockoutEvent($request);

            return $this->sendLockoutResponse($request);
        }

        if ($this->attemptLogin($request)) {
            return $this->sendLoginResponse($request);
        }

        // If the login attempt was unsuccessful we will increment the number of attempts
        // to login and redirect the user back to the login form. Of course, when this
        // user surpasses their maximum number of attempts they will get locked out.
        $this->incrementLoginAttempts($request);

        return $this->sendFailedLoginResponse($request);
    }

Whatever you did in vendor will work here, a trait is to override with custom as needed.

mspace's avatar

This is working for me perfectly. I hope they'll be no side effects along the line. Thank you!

Please or to participate in this conversation.