简体   繁体   English

使用Spatie / laravel权限的Laravel 5.1 ACL

[英]Laravel 5.1 ACL using spatie/laravel-permission

I have read about the policy and gate in laravel 5.1 and coming from 4.2.11. 我已经阅读了有关Laravel 5.1和4.2.11中的策略和门的信息。 A newbie to laravel 5.1. laravel 5.1的新手。

I have a huge project on laravel and i will require to build ACL or the same. 我在laravel上有一个庞大的项目,我将需要构建ACL或相同的版本。 I have tried using this package called spatie/laravel-permission and successfully set it up. 我已经尝试过使用名为spatie / laravel-permission的软件包并成功进行设置。

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 . 我尝试过分配来自php artisan tinker多个角色和权限。

I have a method assignRole() where i want to assign multiple roles and permissions to user assigned directly by admin. 我有一个方法assignRole(),我想向管理员直接分配的用户分配多个角色和权限。

there is assignRole() and givePermissions() method defined in the package, how would i leverage those?? 包中定义了assignRole()和givePermissions()方法,我将如何利用它们?

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 我的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. 尽力而为,但几乎没有提示会有所帮助。

Checkout Laravel Backpack's Permission Manager. 结帐Laravel背包的权限管理器。 It is built on top of spatie/laravel-permission and also provides a nice GUI to manage the permissions. 它建立在spatie / laravel-permission的基础上,还提供了一个不错的GUI来管理权限。 Might be what you need. 可能是您所需要的。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM