本文整理汇总了PHP中app\Permission::whereName方法的典型用法代码示例。如果您正苦于以下问题:PHP Permission::whereName方法的具体用法?PHP Permission::whereName怎么用?PHP Permission::whereName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Permission
的用法示例。
在下文中一共展示了Permission::whereName方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addPermission
/**
* Add a Permission to a Role
*
* @param mixed $permission Permission to add, might by instance of Permission or name of permission as string
* @return Illuminate\Database\Eloquent\Model
*/
public function addPermission($permission)
{
if (is_string($permission)) {
$permission = Permission::whereName($permission)->firstOrFail();
}
return $this->permissions()->save($permission);
}
示例2: postGiveRolePermissions
/**
* Store given permissions to role.
*
* @param \Illuminate\Http\Request $request
*
* @return void
*/
public function postGiveRolePermissions(Request $request)
{
$this->validate($request, ['role' => 'required', 'permissions' => 'required']);
$role = Role::with('permissions')->whereName($request->role)->first();
$role->permissions()->detach();
foreach ($request->permissions as $permission_name) {
$permission = Permission::whereName($permission_name)->first();
$role->givePermissionTo($permission);
}
Session::flash('flash_message', 'Permission granted!');
return redirect('admin/roles');
}
示例3: postUserRolePermissions
/**
* Store given permissions to role.
*
* @param \Illuminate\Http\Request $request
*
* @return void
*/
public function postUserRolePermissions(Request $request)
{
$this->validate($request, ['role' => 'required', 'permissions' => 'required']);
$role = Role::with('permissions')->whereName($request->role)->first();
$role->permissions()->detach();
foreach ($request->permissions as $permission_name) {
$permission = Permission::whereName($permission_name)->first();
$role->assign($permission);
}
\Session::flash('flash_message', 'Permission granted!');
return \Redirect::route('admin.assign-role-permissions', []);
}
示例4: thePermissionWithTheNameHasTheRoleWithTheName
/**
* @Given the permission with the name :arg1 has the role with the name :arg2
*/
public function thePermissionWithTheNameHasTheRoleWithTheName($arg1, $arg2)
{
$permission = Permission::whereName($arg1)->firstOrFail();
$role = Role::whereName($arg2)->firstOrFail();
$permission->addRole($role);
}