本文整理汇总了PHP中app\Role::permissions方法的典型用法代码示例。如果您正苦于以下问题:PHP Role::permissions方法的具体用法?PHP Role::permissions怎么用?PHP Role::permissions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Role
的用法示例。
在下文中一共展示了Role::permissions方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updatePermissions
/**
* Assign permissions to role
*/
public function updatePermissions(Request $request, Role $role)
{
$permissions = $request->checkedPermissions ?: [];
// $permissions = array of submitted permissions OR if all checkboxes were unchecked, make it an empty array
$role->permissions()->sync($permissions);
logThis('Permissions for ' . $role->label . ' changed to ' . $role->permissions()->lists('label'));
return $role->load('permissions');
}
示例2: store
/**
* Method for stroring a new role in the database.
*
* @param RoleRequest $request
* @return mixed
*/
public function store(RoleRequest $request)
{
$role = new Role($request->all());
$role->save();
if (is_null($request->get('permissions'))) {
$role->permissions()->sync([]);
} else {
$role->permissions()->sync($request->get('permissions'));
}
return redirect(route('rbac.roles.index'))->withSuccess('You have successfully created a new role.');
}
示例3: seedDataSource
/**
* Seed Data Source
*
* @author EB
* @return void
*/
protected function seedDataSource()
{
Model::unguard();
$role = new \App\Role();
$role->name = 'rosu';
$role->display_name = 'Read Only Super User';
$role->description = 'Read only user who can see everything';
$role->save();
$permissions = ['merchants-view', 'users-view', 'roles-view', 'locations-view', 'applications-view', 'reports-view'];
foreach ($permissions as $permission) {
try {
$perm = \App\Permission::where('name', '=', $permission)->first();
$role->permissions()->sync([$perm->id], false);
} catch (Exception $e) {
}
}
Model::reguard();
}
示例4: syncPermissions
/**
* Sync up the list of permissions
* @param User $user
* @param array $permissions
* @return void
*/
private function syncPermissions(Role $role, array $permissions)
{
$role->permissions()->sync($permissions);
}