Laravel - Form validation error - argument 2 must be an array

I work with Laravel and every time I submit my form, it gives me this error:

Error in line Factory.php 91: Argument 2 passed to Illuminate \ Validation \ Factory :: make () must be from an array of types, null specified, 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 if I am not trying to send data to the database, it gives me this error. (now it just redirects)

public function store(StoreProjectRequest $request) { return Redirect::to('/index'); } 

Here is how I defined my routes:

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

The line referenced by the error contains 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? Thanks!

+8
php validation forms laravel
source share
1 answer

The problem is with the StoreProjectRequest method and rules() . It should return an array, and in your code, it probably returns something else. Check it out, please.

+11
source share

All Articles