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


PHP Helper::prepPermissions方法代码示例

本文整理汇总了PHP中app\helpers\Helper::prepPermissions方法的典型用法代码示例。如果您正苦于以下问题:PHP Helper::prepPermissions方法的具体用法?PHP Helper::prepPermissions怎么用?PHP Helper::prepPermissions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\helpers\Helper的用法示例。


在下文中一共展示了Helper::prepPermissions方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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

示例2: 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


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