本文整理匯總了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'));
}