Argument 1 passed t be an instance of Illuminate\Http\Request, array given

Stefan Izdrail

Founder & Senior Architect · 2026-06-29

Laravel Company
Title: Argument 1 Passed as Array in Illuminate\Http\Request, Resolving Issue with Code Refactoring Why am I getting the following error?
Argument 1 passed to App\Http\Controllers\Controller::validate() must be an instance of Illuminate\Http\Request, array given, called in app/Http/Controllers/Admin/Auth/AuthController.php on line 72 and defined
When dealing with Laravel controllers and their functions, developers may encounter issues like this one where the function's expected parameter is not passed correctly. In this case, you are receiving an error because the first argument for your controller's validate() function should be of type Illuminate\Http\Request but it actually contains an array. This discrepancy leads to this particular error message. Let's delve further into the code and understand how we can resolve this issue. Functions: The first part of the example seems a bit confusing since two different functions are defined, both containing similar names and parameters. Let's break it down for better understanding and improved coding practices.
protected function loginValidation($request)
{
    $rules = array(
      'fname' => 'required|max:255',
      'lname'  => 'required|max:255',
      'email'      => 'required|email|max:255|unique:users',
      'password'   => 'required|min:6|confirmed',
    );
    $this->validate( $request , $rules);
}
protected function getLoginCredentials(Request $request)
{
    $validator = $this->loginValidation(Request::all());

    if($validator->passes())
    {
    return[
    'email'    => Request::input('email'),
    'password' => Request::input('password'),
    'type'     => 1  
    ];

    return true;
    }else{
        return redirect()->back()->withErrors();
    }
}
This simplifies the code and maintains a clearer structure. The loginValidation() function is responsible for defining the validation rules, which might be used in other functions or contexts. Here we're using it to validate user input, which can be called directly within your controller as `$this->loginValidation($request);`. Updated Code: The error you are facing could be because of mixing these two functions. If you want to keep both loginValidation() and getLoginCredentials(), the first one should be used in your controller methods, not inside the getLoginCredentials(). This might result in a more manageable code with minimal errors.
public function validate($request, $rules)
{
    $rules = array(
      'fname' => 'required|max:255',
      'lname'  => 'required|max:255',
      'email'      => 'required|email|max:255|unique:users',
      'password'   => 'required|min:6|confirmed',
    );
    $this->validate( $request , $rules);
}

protected function getLoginCredentials()
{
    return [
    'email'    => Request::input('email'),
    'password' => Request::input('password'),
    'type'     => 1  
    ];
}
Error: The error you mentioned is not related to your initial code. It looks like a different issue where the function validate() definition in the class is incorrect. The declaration should be:
Declaration of App\Http\Controllers\Admin\Auth\AuthController::validate() should be compatible with App\Http\Controllers\Controller::validate(Illuminate\Http\Request $request, array $rules, array $messages = Array, array $customAttributes = Array)
To fix this error, make sure your controller's validate() function definition follows the correct syntax. You can refer to Laravel's official documentation for a more detailed explanation on how to use controllers and their functions effectively. In Conclusion: The initial error you encountered was caused by mixing up different functions within your code. By separating them, refactoring your controller, and ensuring the correct function signatures, you should be able to resolve this issue and have a cleaner codebase. Remember to also check for other potential conflicts or problems in your project as they might affect the overall performance and stability of your application.