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)
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);
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();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With