Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel - Error "Argument 2 passed to Illuminate\Validation\Factory::make() must be of the type array, object given"

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

like image 496
Tintin Avatar asked Dec 14 '22 13:12

Tintin


1 Answers

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;
}
like image 196
Nikola Gavric Avatar answered Dec 17 '22 23:12

Nikola Gavric