Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

Functions:

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());

    var_dump($validator); die();

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

    return true;
    }else{
        return redirect()->back()->withErrors();
    }
  }  

Updated Code:

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(Request $request)
  {
    $validator = $this->validate($request, $rules);

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

    return true;
    }else{
        return redirect()->back()->withErrors();
    }
  }  

Error:

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)
like image 945
Jess McKenzie Avatar asked Mar 19 '16 22:03

Jess McKenzie


1 Answers

Change to

 $validator = $this->loginValidation($request);

With this you pass an instance of Request to the validate function

you are passing an array to the first argument of the validate function which i guess should be an instance of Request

$this->validate( $request , $rules);

Updated

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);

   var_dump($validator); die();

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

      return true;
   }else{
      return redirect()->back()->withErrors();
   }
}  
like image 113
oseintow Avatar answered Nov 14 '22 12:11

oseintow