11

I'm working with Laravel and every time I submit my form it gives me this error:

ErrorException in Factory.php line 91: Argument 2 passed to Illuminate\Validation\Factory::make() must be of the type array, null given, called in /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/FormRequest.php on line 83 and defined

This is some code for the controller, even when I don't try to send data to the database it gives me this error. (now it's just redirecting)

public function store(StoreProjectRequest $request)
{


    return Redirect::to('/index');

}

This is how I defined my routes:

Route::get('/projects','ProjectsController@index');
Route::get('/create','ProjectsController@create');

Route::post('/create','ProjectsController@store');

The line the error refers to is what is in the return section here:

protected function getValidatorInstance()
{
    $factory = $this->container->make('Illuminate\Validation\Factory');

    if (method_exists($this, 'validator')) {
        return $this->container->call([$this, 'validator'], compact('factory'));
    }

    return $factory->make(
        $this->all(), $this->container->call([$this, 'rules']), $this->messages(), $this->attributes()
    );
}

Can anyone help me? Thank you!

3
  • You need to post the code for your Validator::make(). Make sure the first parameter is the input array eg: $request->all() and the second parameter is your rules array eg: ['email' => 'required|email'...] Commented Oct 15, 2015 at 0:15
  • thank you for posting this question!!! Commented Apr 28, 2016 at 10:45
  • I had a partial installation of the framework which produced exactly this same error. I copied all the files across again (restoring missing files) and then the problem went away. Commented Feb 7, 2018 at 9:36

2 Answers 2

19

Problem is in your StoreProjectRequest and it's rules() method. It should return array and in your code it probably returns something else. Check it, please.

Sign up to request clarification or add additional context in comments.

1 Comment

you saved my day Maxim. Newbie for laravel. Thanks a ton!!! By mistake i deleted return statement as it was giving error.
0

Got similar error for Maatwebsite\Excel\Imports\ModelManager::add(): Argument #2 ($attributes) must be of type array, null given.

Used WithValidation class method public function prepareForValidation($data, $index), but made the mistake not adding return $data inside this method.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.