What's wrong with this code ?
class DeleteDetail extends FormRequest {
public function authorize() {
return true;
}
public function rules() {
$request = Request::all();
$rules = [
'hobby' => [
'string',
'between:3,20',
Rule::exists('user_hobby')->where(function ($query) use ($request) {
$query->where('hobby', $request['hobby'])->where('user_id', Auth::user()->id);
}),
],
];
return Validator::make($request, $rules);
}
}
Error that I'm getting :
Argument 2 passed to Illuminate\Validation\Factory::make() must be of the type array, object given
You are returning the wrong value from inside the rules
method itself, you should return the array containing your validation rules
instead of Validation::make
:
public function rules() {
...
return $rules;
}
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