本文整理汇总了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');
}
示例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);
}
}