I have read about the policy and gate in laravel 5.1 and coming from 4.2.11. A newbie to laravel 5.1.
I have a huge project on laravel and i will require to build ACL or the same. I have tried using this package called spatie/laravel-permission and successfully set it up.
I then went ahead and tried to figure out that a the migrations are created and you get some boiler plate out of the box.
Though i am failing in terms of understanding, that what if the admin want to assign multiple roles and permissions directly from the frontend with some methods in controllers, how would one do it?
I have tried assigning ,multiple roles and permission from php artisan tinker
.
I have a method assignRole() where i want to assign multiple roles and permissions to user assigned directly by admin.
there is assignRole() and givePermissions() method defined in the package, how would i leverage those??
As per the Models are concerned , i have tried in my template
@foreach($users as $user )
{{$user->email}}
@foreach($user->roles as $role)
{{$role->name}}
@endforeach
@foreach($user->permisssions as $permission )
{{$permission->name}}
@endforeach
@endforeach
This shows me the authenticated users permissions.
my controller.php
public function showRolesandpermission(){
$users = Auth::user();
return view("admin.assignrole", compact("users"));
}
public function update(Request $request, $id){
$user = User::whereID($id)->firstOrFail();
if(count($user)>0)
{
$roles = [];
$permissions = [];
foreach(Role::all() as $r)
{
$roles[$r->id] = $r->name;
}
foreach(Permission::all() as $permissions)
{
$permissions[$permissions->id] = $permissions->name;
}
$role1 = Request::get("role");
$perm = Request::get("permissions");
if(isset($role1) && isset($perm)){
$user->roles->update([
$request->name = $request->name
]);
$user->permissions->update([
$request->name = $request->name
]);
$user->save();
return redirect::back();
}
}
}
How can i leverage this and edit the users permission directly from the frontend it self ?? How can we use something like multi-select and update the users roles and permission.
Trying hard, but little hint would help.