本文整理汇总了PHP中app\models\Permission::get方法的典型用法代码示例。如果您正苦于以下问题:PHP Permission::get方法的具体用法?PHP Permission::get怎么用?PHP Permission::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Permission
的用法示例。
在下文中一共展示了Permission::get方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: show
public function show($id)
{
if (Auth::user()->can('read-role')) {
$data['role'] = Role::find($id);
$data['title'] = "Role \"" . $data['role']->display_name . "\"";
$data['menu_actions'] = [Form::editItem(route('roles.edit', $id), 'Edit This Role', Auth::user()->can('update-role'))];
$permissions = Permission::get();
$permissions_in_role = Permission::whereHas('roles', function ($q) use($id) {
$q->where('roles.id', $id);
})->get();
$counter = 0;
foreach ($permissions as $permission) {
$is_in_role = false;
foreach ($permissions_in_role as $permission_in_role) {
if ($permission->id == $permission_in_role->id) {
$is_in_role = true;
}
}
$data['permissions'][$counter] = $permission;
$data['permissions'][$counter]['is_in_role'] = $is_in_role;
$counter++;
}
return view('roles/show', $data);
} else {
return redirect()->back()->withErrors(['Access denied to roles show page']);
}
}
示例2: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Role::create(['name' => 'Admin', 'display_name' => '超级管理员']);
Role::create(['name' => 'Editor', 'display_name' => '编辑']);
Role::create(['name' => 'Demo', 'display_name' => '演示']);
Role::get()->each(function ($role) {
if ($role->name === 'Admin') {
$permissions = Permission::get()->pluck('id')->all();
$role->perms()->sync($permissions);
}
if ($role->name === 'Editor') {
$permissions = Permission::where('name', 'manage_contents')->first();
$role->perms()->sync([$permissions->id]);
}
});
}
示例3: assign_per_role
public function assign_per_role()
{
$roles = Role::get(['id', 'name']);
$permissions = Permission::get(['id', 'name']);
return view('assign_per_role', compact('roles', 'permissions'));
}
示例4: index
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$permission = Permission::get();
return response()->json(["msg" => "Success", "items" => $permission], 200);
}