trevorg
335
3
Laravel

Issue with validating input arrays (such as multiple select fields)

Posted 3 years ago by trevorg

So in my blade template I have this input: {!! Form::select('bookids[]', $books->lists('name','id'), null, ['multiple']) !!}

And then I'm validating it with a validation rule:

'bookids' => ['array','exists:book,id,user_id,'.\Auth::user()->id]

It works great. However, if the validation fails, Laravel chokes when sending back the error data to the view, I believe because it is not expecting to receive an array, but a string for each input field:

htmlentities() expects parameter 1 to be string, array given

Is there a workaround for this?

Please sign in or create an account to participate in this conversation.