dsg435665475 2016-05-16 17:35
浏览 50

使用spatie / laravel-permission的Laravel 5.1 ACL

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.

  • 写回答

1条回答 默认 最新

  • douren1928 2016-06-15 08:40
    关注

    Checkout Laravel Backpack's Permission Manager. It is built on top of spatie/laravel-permission and also provides a nice GUI to manage the permissions. Might be what you need.

    https://github.com/Laravel-Backpack/permissionmanager

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?