当前位置: 首页>>代码示例>>PHP>>正文


PHP Sentinel::findRoleById方法代码示例

本文整理汇总了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);
 }
开发者ID:notegame,项目名称:eztool,代码行数:18,代码来源:ACLManagerController.php

示例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');
 }
开发者ID:umahatokula,项目名称:academia,代码行数:25,代码来源:rolesController.php

示例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);
     }
 }
开发者ID:vuthaihoc,项目名称:soa-sentinel,代码行数:21,代码来源:Roles.php

示例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;
 }
开发者ID:Okipa,项目名称:una.app,代码行数:25,代码来源:Role.php

示例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');
 }
开发者ID:SawMaineK,项目名称:josh-admin,代码行数:36,代码来源:SentinelUpdateSeeder.php

示例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);
            }
        }
开发者ID:Jarboe,项目名称:Users-component,代码行数:31,代码来源:group_permissions.php

示例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);
     }
 }
开发者ID:umahatokula,项目名称:academia,代码行数:48,代码来源:usersController.php

示例8: getRolePermissions

 public static function getRolePermissions($role_id)
 {
     return array_keys(\Sentinel::findRoleById($role_id)->permissions);
 }
开发者ID:umahatokula,项目名称:academia,代码行数:4,代码来源:Helper.php

示例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);
}));
开发者ID:Jarboe,项目名称:Users-component,代码行数:7,代码来源:groups.php


注:本文中的Sentinel::findRoleById方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。