Anyone?
Empty input values in rules() method of FormRequest
Hello everyone!
I have a strange issue. I can't access input parameters in rules method of FormRequest. The following code returns empty array:
public function rules()
{
dd($this->all());
$rules = [
'name' => 'required|min:5|max:255|unique:products,name,' . $this->get('id'),
'sku' => 'required|max:255|unique:products,sku,' . $this->get('id'),
'slug' => 'required|max:255|unique:products,slug,' . $this->get('id'),
'price' => 'required|numeric',
];
/*foreach ($this->input('variations') as $index => $variation) {
$rules['variations.' . $index . 'sku'] = 'unique:variations,sku,' . $this->input('productVariationIDs')[$index];
}
dd($rules);*/
return $rules;
}
However if I try to access the same input inside the other method of the class then I get it without any issue. For example in the authorize method:
public function authorize()
{dd($this->all());
// only allow updates if the user is logged in
return backpack_auth()->check();
}
I also find out that rules() method is called before authorize(), so I assume that request is not fully instantiated. But this is very strange as after googling I couldn't find anybody with the same issue.
So my question is how can I access input parameters inside the rules() method of class that extends FormRequest class?
This is Laravel 5.7 with installed Backpack.
Please or to participate in this conversation.