Ad

Dynamic Field Names In Laravel 5.1

- 1 answer

I need to create a checkbox in Laravel 5.1 with a name like so:

<input type="checkbox" name="groups[1]">
<input type="checkbox" name="groups[2]">

I am using the following code, but it doesn't work. Does anyone know the correct way to code this?

{!! Form::checkbox('groups[{{ $user->id }}]', 'administrator', in_array('Administrator', $user->roles()->lists('name')->toArray())) !!}

The output I get is:

<input checked="checked" name="groups[<?php echo e($user->email); ?>]" value="administrator" type="checkbox">
Ad

Answer

You cannot use blade inside php. Just concatinate the id as normal.

Try this:

Form::checkbox('groups['.$user->id.']', 'administrator', in_array('Administrator', $user->roles()->lists('name')->toArray())) !!}
Ad
source: stackoverflow.com
Ad