Support the ongoing development of Laravel.io →
Database Eloquent Views
Last updated 2 years ago.
0

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');
Last updated 2 years ago.
0

You can also use the sync() function

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.