I have some validation on my form in laravel to ensure the gift the user is claiming is one assigned to their campaign with the below code
'gift_id' => 'required|int|exists:gifts,campaign_id,' . \Auth::user()->campaign->id,
But on form submission I am getting the following error
ErrorException in ValidatesAttributes.php line 721: Undefined offset: 1
Could someone please help me out?
Thanks
The Laravel application I'm currently working on started to throw that exception. In my case, the issue was slightly different. This was my original code:
// ...
'extension_id' => [
'nullable',
'int',
Rule::exists('extensions,id'),
],
// ...
I added that ,id to the table name hoping that the correct column name was used when the framework checks the value existence. However, it didn't work as expected. I got that exception from Illuminate\Validation\Concerns\ValidatesAttributes class.
Undefined offset: 1
After some attempts, I finally was able to overcome the error by passing two arguments to the rule, instead of a single string:
Rule::exists('extensions', 'id'),
I know that's not the same case as the OP, but I guess it can help others that reach this same question as I did.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With