web-dev-qa-db-fra.com

L'argument 1 passé est une instance de Illuminate\Http\Request, tableau donné

Pourquoi est-ce que je reçois l'erreur suivante?

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

Les fonctions:

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

Code mis à jour:

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

Erreur:

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)
5
Jess McKenzie

Changer en 

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

Avec cela, vous passez une instance de Request à la fonction validate

vous passez un tableau au premier argument de la fonction validate qui, je suppose, devrait être une instance de Request

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

Mis à jour

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();
   }
}  
2
oseintow