Laravel - Form validation error - argument 2 must be array
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
Laravel Form Validation Error: Decoding "Argument 2 must be array, null given"
As a senior developer working with the Laravel ecosystem, we often encounter errors that seem cryptic but point to fundamental misunderstandings of how the framework handles data flow. Today, we are diving deep into a very specific and frustrating error: Argument 2 passed to Illuminate\Validation\Factory::make() must be of the type array, null given.
This issue frequently surfaces when dealing with form requests, custom validation logic, or complex data interactions. While the error message itself seems to point towards an internal factory issue, understanding where that null is originating is the key to a robust solution.
Understanding the Error Context
The error you are seeing—Argument 2 passed to Illuminate\Validation\Factory::make() must be of the type array, null given—is happening deep within Laravel’s validation machinery. It indicates that somewhere in the chain where the validation rules are being assembled (likely inside a FormRequest or related trait), the method responsible for providing the validation rules is returning null instead of an expected array of rules.
In your provided context, the error points to the line where you are creating the validator instance:
$factory = $this->container->make('Illuminate\Validation\Factory');
// ...
return $factory->make(
$this->all(), // Argument 1 (data)
$this->container->call([$this, 'rules']), // Argument 2 (rules) <-- This is where the null is likely injected
$this->messages(),
$this->attributes()
);
The framework expects the second argument to be an array containing the validation rules. If $this->container->call([$this, 'rules']) returns null, the factory throws this exception because it cannot process a non-array input as validation rules.
The Root Cause: Missing or Incorrect Rules Definition
This issue almost always stems from one of two places within your FormRequest class:
- Missing Validation Rules: You have defined methods for rules, but they are not being correctly populated when the validator factory calls them.
- Conditional Logic Failure: The logic that determines which rules to apply is failing under certain conditions, resulting in an empty or null return value instead of an array of rules.
Since you are dealing with a custom setup (indicated by methods like getValidatorInstance() and using the container), we need to ensure that every path returns a valid array structure, even if it's an empty one.
Practical Solution: Ensuring Array Return Values
The fix involves explicitly ensuring that your rule-gathering methods always return an array, even if that array is empty, rather than returning null.
Let’s look at how you might define the necessary data within a FormRequest to prevent this issue. If you are using custom helper methods to gather rules (like $this->rules()), ensure these methods are structured correctly.
Example of Safe Rule Retrieval:
Instead of relying on a method that might return null, structure your logic to default to an empty array:
// Inside your FormRequest class or trait where the validator is built
protected function getRules(): array
{
// Always start with an empty array as a safe fallback
$rules = [];
// Add your specific validation rules here
if ($this->hasCustomRules()) {
$rules = array_merge($rules, $this->customValidationRules());
}
// Ensure the result is always an array
return $rules;
}
protected function getValidatorInstance()
{
$factory = $this->container->make('Illuminate\Validation\Factory');
if (method_exists($this, 'validator')) {
// If you are using the standard Laravel validator setup, use it directly.
return $this->container->call([$this, 'validator'], compact('factory'));
}
return $factory->make(
$this->all(),
$this->getRules(), // Use the safe method defined above
$this->messages(),
$this->attributes()
);
}
By explicitly defining a method (getRules() in this example) that guarantees an array return, you eliminate the possibility of passing null into the validation factory, resolving the error cleanly. This practice aligns perfectly with Laravel's focus on clear data contracts and robust dependency handling, which is central to good architectural design (see principles discussed at laravelcompany.com).
Conclusion
The error "Argument 2 must be array, null given" is a symptom of a missing type check in your custom validation assembly process. By rigorously ensuring that all methods responsible for gathering validation rules return an array—even if it's empty—you safeguard the internal framework components and ensure your application remains stable. Always default to safe data types when building complex systems like form requests. Happy coding!