I did this
edit.blade.php
{{ Form::model($role->first(), ['role' => 'form', 'url' => '/admin/roles/' . $role->first()->id, 'method' => 'PUT']) }}
<div class='form-group'>
{{ Form::label('name', 'Nome') }}
{{ Form::text('name', null, ['placeholder' => 'Nome', 'class' => 'form-control']) }}
</div>
@foreach ($perms as $perm)
<div class='form-group'>
{{Form::label('perm_name'.$perm->id, $perm->name );}}
{{Form::label('perm_name_d'.$perm->id, $perm->display_name );}}
{{Form::checkbox( $perm->id, $perm->id, $permRole->contains($perm->id) ? 1 : 0); }}
</div>
@endforeach
<div class='form-group'>
{{ Form::submit('Actualizar', ['class' => 'btn btn-primary']) }}
</div>
{{ Form::close() }}
Controller.php
edit function
$perms = Permission::all();
$role = Role::whereId($id)->get();
$permRole = $role->first()->permissions()->get();
return View::make('admin.roles.edit', [ 'role' => $role, 'perms' => $perms, 'permRole' => $permRole ]);
update function
$permissions = Permission::all();
$role = Role::find($id);
$role->name = Input::get('name');
$role->save();
$role->permissions()->detach();
foreach ($permissions as $key) {
if (Input::has($key->id)) {
$role->permissions()->attach($key->id);
}
}
return Redirect::to('/admin/roles');
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community