Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel - Form validation error - argument 2 must be array

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!

like image 616
Anhinga Avatar asked Oct 14 '15 21:10

Anhinga


1 Answers

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.

like image 138
Maxim Lanin Avatar answered Sep 27 '22 15:09

Maxim Lanin