本文整理汇总了PHP中app\Permission::roles方法的典型用法代码示例。如果您正苦于以下问题:PHP Permission::roles方法的具体用法?PHP Permission::roles怎么用?PHP Permission::roles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Permission
的用法示例。
在下文中一共展示了Permission::roles方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
/**
* Method for stroring a new permission in the database.
*
* @param PermissionRequest $request
* @return mixed
*/
public function store(PermissionRequest $request)
{
$permission = new Permission($request->all());
$permission->save();
if (is_null($request->get('roles'))) {
$permission->roles()->sync([]);
} else {
$permission->roles()->sync($request->get('roles'));
}
$routes = $request->get('routes');
foreach ($routes as $route) {
$permission->routes()->create(['route' => $route]);
}
return redirect(route('rbac.permissions.index'))->withSuccess('You have successfully created a new permission.');
}
示例2: seedDataSource
/**
* Seed Data Source
*
* @author SL
* @return void
*/
protected function seedDataSource()
{
Model::unguard();
$permission = new \App\Permission();
$permission->name = 'applications-merchant-payments';
$permission->display_name = 'Merchant Payments';
$permission->description = 'merchant payments';
$permission->save();
$roles = ['manager', 'su', 'administrator'];
foreach ($roles as $roleName) {
try {
$role = \App\Role::where('name', '=', $roleName)->first();
$permission->roles()->attach($role->id);
} catch (Exception $e) {
}
}
$permission->save();
Model::reguard();
}
示例3: edit
/**
* Show the form for editing the specified resource.
*
* @param App\Permission $permission
* @return Response
*/
public function edit($permission)
{
$current_roles = array_pluck($permission->roles()->get(['roles.id'])->toArray(), 'id');
return view('templates.' . \Config::get('webpanel.template') . 'webpanel.panel.permissions.edit', compact('permission', 'current_roles'));
}