Yes.
I use this technic to work with Many-to-Many relationships.
Let's say you have a role-permission model.
<div class = "form-group">
{{ Form::label('Permissions') }}
<?php $permissions = Permission::all();
$allowed = $role->permissions->lists('id');
$value = false;?>
@foreach($permissions as $permission)
<?php $value = in_array($permission->id, $allowed);?>
<div class = "checkbox">
<label>
{{ Form::checkbox('allowed[]', $permission->id, $value) }} {{ $permission->ime }}
</label>
</div>
@endforeach
</div>
Inside the controller I have
$input = Input::all();
if(isset($input['allowed']))
$allowed = $input['allowed'];
else $allowed = array();
if(!$allowed || !is_array($allowed))
$allowed = array();
if(count($allowed) > 0)
$allowed = Permission::select('id')
->whereIn('id', $allowed)
->get()
->lists('id');
if(count($allowed) > 0)
$this->permissions()->sync($allowed);
else $this->permissions()->detach();
I hope this is what you were looking for.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community