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