本文整理汇总了PHP中Sentinel::findRoleById方法的典型用法代码示例。如果您正苦于以下问题:PHP Sentinel::findRoleById方法的具体用法?PHP Sentinel::findRoleById怎么用?PHP Sentinel::findRoleById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sentinel
的用法示例。
在下文中一共展示了Sentinel::findRoleById方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
public function store(Request $request)
{
if (!Sentinel::hasAccess(config('eztool.acl.permissions.update'))) {
abort(401, 'no permissions to access');
}
$roles = $request->get('role');
if ($roles) {
foreach ($roles as $role_id => $permissions) {
foreach ($permissions as $permission => $value) {
$permissions[$permission] = (bool) $value;
}
$role = \Sentinel::findRoleById($role_id);
$role->permissions = $permissions;
$role->save();
}
}
return response()->json(true);
}
示例2: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
// dd($request->assign_permission);
//array to hold final permission values
$array_of_permissions = Helper::prepPermissions($request->assign_permission, 'true');
//create new role
$role = \Sentinel::getRoleRepository()->createModel()->create(['name' => $request->role, 'slug' => Helper::makeSlug($request->role)]);
//retreive id of last inserted role
$role_id = $role->id;
$role = \Sentinel::findRoleById($role_id);
//assign permissions to role
$role->permissions = $array_of_permissions;
$role->save();
//assign newly created role to coder
$credentials = ['login' => 'umahatokula@ovalsofttechnologies.com'];
$user = \Sentinel::findByCredentials($credentials);
$role->users()->attach($user);
return \Redirect::to('settings/roles');
}
示例3: save
public function save()
{
$name = $this->name();
//fetch the selected roles from the temporary
//form field
$input = \Input::all();
$selected_roles = array_get($input, $name);
if ($selected_roles === null) {
$selected_roles = [];
}
//remove all roles
foreach ($this->instance()->roles->toArray() as $key => $value) {
$role = \Sentinel::findRoleById($value['id']);
$this->instance()->roles()->detach($role);
}
//add only the new selected
foreach ($selected_roles as $key => $id) {
$role = \Sentinel::findRoleById($id);
$this->instance()->roles()->attach($role);
}
}
示例4: updateHierarchy
/**
* @param int $parent_role_id
* @return int
*/
public function updateHierarchy($parent_role_id)
{
// we get the roles concerned by the rank incrementation regarding the given parent role
if ($parent_role = \Sentinel::findRoleById($parent_role_id)) {
// if a parent is defined
// we get the roles hierarchically inferiors to the parent
$roles = \Sentinel::getRoleRepository()->where('rank', '>', $parent_role->rank)->orderBy('rank', 'desc')->get();
} else {
// if the role has to be the master role
// we get all roles
$roles = \Sentinel::getRoleRepository()->orderBy('rank', 'desc')->get();
}
// we increment the rank of the selected roles
foreach ($roles as $r) {
$r->rank += 1;
$r->save();
}
// we get the new rank to apply to the current role
$new_rank = $parent_role ? $parent_role->rank + 1 : 1;
return $new_rank;
}
示例5: run
public function run()
{
/* move all groups to roles table */
$groups = DB::select('select * from groups');
foreach ($groups as $group) {
$id = $group->id;
$name = $group->name;
$slug = str_slug($name);
if ($group->id == '1') {
$permissions = array('admin' => 1);
} else {
$permissions = array();
}
Sentinel::getRoleRepository()->createModel()->create(['id' => $id, 'name' => $name, 'slug' => $slug, 'permissions' => $permissions]);
}
/* move users_groups data into role_users table */
$users_groups = DB::select('select * from users_groups');
foreach ($users_groups as $user_group) {
$user = Sentinel::findById($user_group->user_id);
$group = DB::table('groups')->where('id', '=', $user_group->group_id)->first();
$role_current = DB::table('roles')->where('name', '=', $group->name)->first();
$role = Sentinel::findRoleById($role_current->id);
$role->users()->attach($user);
}
$this->command->info('groups, users_groups successfully migrated to roles, role_users tables');
/* insert each user into activations table */
$users = DB::select('select * from users');
foreach ($users as $user) {
$current_user = Sentinel::findById($user->id);
$activation = Activation::create($current_user);
if ($user->activated) {
Activation::complete($current_user, $activation->code);
}
}
$this->command->info('activations created successfully');
}
示例6: switch
switch ($permission) {
case 'allow':
$group->addPermission($ident);
break;
case 'deny':
$group->addPermission($ident, false);
break;
default:
$msg = 'Not allowed permission [' . $permission . '] for [' . $ident . ']';
throw new \RuntimeException($msg);
}
}
}
$group->save();
}, 'update' => function ($idRow, $patternValues, $values) {
$group = \Sentinel::findRoleById($idRow);
foreach ($patternValues as $permissionGroup => $permissionActions) {
foreach ($permissionActions as $permissionAction => $permission) {
$ident = $permissionGroup . '.' . $permissionAction;
switch ($permission) {
case 'allow':
$group->addPermission($ident);
break;
case 'deny':
$group->addPermission($ident, false);
break;
default:
$msg = 'Not allowed permission [' . $permission . '] for [' . $ident . ']';
throw new \RuntimeException($msg);
}
}
示例7: update
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
// dd($request);
//get user u ant to update
$user = \Sentinel::findById($id);
//get the persons details
$staff = Staff::find($request->user);
$data = $request->except('_token');
$rules = ['password' => 'min:4|required'];
$validator = \Validator::make($data, $rules);
if ($validator->passes()) {
//array to hold final permission values
$array_of_permissions = Helper::prepPermissions($request->exempt_permission, 'false');
$credentials = ['email' => $staff->email, 'password' => $request->password, 'permissions' => $array_of_permissions, 'staff_id' => $staff->id, 'first_name' => $staff->fname, 'last_name' => $staff->lname];
//update user
$user = \Sentinel::update($user, $credentials);
//get the id(s) of the current roles of this user in an array
$current_roles = array();
foreach ($user->roles as $value) {
$current_roles[] = $value->id;
}
//compute role(s) to add
$add_roles = array_diff($request->assign_roles, $current_roles);
//compute role(s) to delete
$delete_roles = array_diff($current_roles, $request->assign_roles);
//update user role(s)
$user = \Sentinel::findById($user->id);
//add ne role(s)
foreach ($add_roles as $role_id) {
$role = \Sentinel::findRoleById($role_id);
$role->users()->attach($user);
}
//delete role(s), if any
foreach ($delete_roles as $role_id) {
\DB::table('role_users')->where('role_id', $role_id)->where('user_id', $user->id)->delete();
}
return \Redirect::to('settings/users/create');
} else {
return \Redirect::back()->withInput()->withErrors($validator);
}
}
示例8: getRolePermissions
public static function getRolePermissions($role_id)
{
return array_keys(\Sentinel::findRoleById($role_id)->permissions);
}
示例9: array
<?php
return array('db' => array('table' => 'roles', 'order' => array('id' => 'ASC'), 'pagination' => array('per_page' => 12)), 'options' => array('caption' => 'Группы пользователей'), 'position' => array('tabs' => array('Info' => array('slug', 'name'), 'Permissions' => array('pattern.group_permissions'))), 'fields' => array('id' => array('caption' => '#', 'type' => 'readonly', 'class' => 'col-id', 'width' => '1%', 'hide' => true, 'is_sorting' => true), 'slug' => array('caption' => 'Идентификатор', 'type' => 'text', 'filter' => 'text', 'is_sorting' => true, 'validation' => array('server' => array('rules' => 'required'), 'client' => array('rules' => array('required' => true), 'messages' => array('required' => 'Обязательно к заполнению')))), 'name' => array('caption' => 'Название', 'type' => 'text', 'filter' => 'text', 'is_sorting' => true), 'pattern.group_permissions' => ['caption' => 'Права', 'hide_list' => true]), 'actions' => array('search' => array('caption' => 'Поиск'), 'insert' => array('caption' => 'Добавить'), 'update' => array('caption' => 'Редактировать'), 'delete' => array('caption' => 'Удалить')), 'callbacks' => array('handleDeleteRow' => function ($id) {
$role = \Sentinel::findRoleById($id);
$role->delete();
return array('id' => $id, 'status' => true);
}));