Dynamic Art's Dynamic Art's - 1 year ago 79
PHP Question

Php array from multiple checkbox

I'm working with laravel, and I'm a bit stuck in getting the right structure I want of the value, so I have a check box like this:

<input type="checkbox" name="permission[]" value="{{$permission->slug}}"> {{$permission->name}}

And this outputs me this:

array:2 [
0 => "dashboard.view"
1 => "user.edit"

But what I really need to store is something like this:


Answer Source

This should be what you're looking for:

<input type="checkbox"  name="permission[{{$permission->slug}}]" value="true"> {{$permission->name}}

Should give you an associative array on the backend you can call json_encode on if you need to store it as a json object.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download