本文整理汇总了PHP中Sentinel::getPermissionProvider方法的典型用法代码示例。如果您正苦于以下问题:PHP Sentinel::getPermissionProvider方法的具体用法?PHP Sentinel::getPermissionProvider怎么用?PHP Sentinel::getPermissionProvider使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sentinel
的用法示例。
在下文中一共展示了Sentinel::getPermissionProvider方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updateUserGroups
public function updateUserGroups($userID, array $groupIDs)
{
$userGroups = \Sentinel::getUserGroupProvider()->findGroupsByUserID($userID)->pluck('group_id')->toArray();
$groupsHaveChanged = false;
$groupsToAdd = array_diff($groupIDs, $userGroups);
if (!empty($groupsToAdd)) {
$groupsHaveChanged = true;
foreach ($groupsToAdd as $newUserGroup) {
\Sentinel::getUserGroupProvider()->attach($userID, $newUserGroup);
\Sentinel::getPermissionProvider()->addUserGroupPermissions($userID, $newUserGroup);
}
}
$groupsToRemove = array_diff($userGroups, $groupIDs);
if (!empty($groupsToRemove)) {
$groupsHaveChanged = true;
foreach ($groupsToRemove as $oldUserGroup) {
\Sentinel::getUserGroupProvider()->detach($userID, $oldUserGroup);
\Sentinel::getPermissionProvider()->removeUserGroupPermissions($userID, $oldUserGroup);
}
}
return $groupsHaveChanged;
}
示例2: updateUser
/**
* Updating a user and his person table + group table info.
*
* @param int $id
* @param array $data
*
* @return void
*/
public function updateUser($id, array $data)
{
if (!empty($id) && !empty($data)) {
$this->createModel()->newQuery()->where('id', $id)->update(array('name' => $data['name'], 'email' => $data['email']));
unset($data['name'], $data['email']);
$personID = \Spirit::getPersonProvider()->getPersonByUserId($id)->select(['id as user_id'])->value('user_id');
if (!is_null($personID)) {
if (!isset($data['groups'])) {
$data['groups'] = [];
}
$groupsHaveChanged = \Sentinel::getGroupProvider()->updateUserGroups($id, $data['groups']);
if ($groupsHaveChanged === true) {
\Sentinel::getPermissionProvider()->updateUserGroupPermissions($id, $data['groups']);
}
unset($data['groups']);
\Spirit::getPersonProvider()->updatePerson($personID, $data);
} else {
throw new \UnexpectedValueException('User ' . $id . ' not found for update');
}
} else {
throw new \UnexpectedValueException('Invalid data for user update');
}
}