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


PHP Permission::preparePermissionsForSave方法代码示例

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


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

示例1: postEdit

 /**
  * Update the specified resource in storage.
  *
  * @param $role
  * @return Response
  */
 public function postEdit(Request $request, $role)
 {
     // Declare the rules for the form validation
     $rules = array('name' => 'required|unique:roles', 'display_name' => 'required|unique:roles');
     // Validate the inputs
     //         $validator = Validator::make($request->all(), $rules, [
     //         	'name.required' => 'A name is required.',
     //         	'name.unique' => 'Please use a different name.',
     //         	'display_name.required' => 'A display name is required',
     //         	'display_name.unique' => 'Please use a different display name.'
     //         ]);
     $name = $request->input('name');
     $display_name = $request->input('display_name');
     // Check if the form validates with success
     //         if ($validator->passes())
     //         {
     //             // Update the role data
     //             $role->name = $request->input('name');
     //             $role->display_name = $request->input('display_name');
     //             $role->is_protected = $request->has('is_protected') ? 1 : 0;
     //             $role->perms()->sync($this->permission->preparePermissionsForSave($request->input('permissions')));
     //             // Was the role updated?
     //             if ($role->save())
     //             {
     //                 // Redirect to the role page
     //                 return redirect('admin/roles/' . $role->id . '/edit')->with('success', 'Role updated');
     //             }
     //             else
     //             {
     //                 // Redirect to the role page
     //                 return redirect('admin/roles/' . $role->id . '/edit')->with('error', 'Could not update role');
     //             }
     //         }
     if (!empty($name) && $name != $role->name) {
         $nameValidator = Validator::make(['name' => $name], ['name' => 'required|unique:roles'], ['name.required' => 'A name is required.', 'name.unique' => 'Please use a different name.']);
         if ($nameValidator->passes()) {
             $role->name = $name;
             $role->perms()->sync($this->permission->preparePermissionsForSave($request->input('permissions')));
             if ($role->save()) {
                 // Redirect to the role page
                 return redirect('admin/roles/' . $role->id . '/edit')->with('success', 'Role updated');
             } else {
                 // Redirect to the role page
                 return redirect('admin/roles/' . $role->id . '/edit')->with('error', 'Could not update role');
             }
         }
     }
     if (!empty($display_name) && $display_name != $role->display_name) {
         $displayNameValidator = Validator::make(['display_name' => $display_name], ['display_name' => 'required|unique:roles'], ['display_name.required' => 'A display name is required.', 'display_name.unique' => 'Please use a different display name.']);
         if ($displayNameValidator->passes()) {
             $role->display_name = $display_name;
             $role->perms()->sync($this->permission->preparePermissionsForSave($request->input('permissions')));
             if ($role->save()) {
                 // Redirect to the role page
                 Flash::success('Role updated');
                 return redirect('admin/roles/' . $role->id . '/edit');
             } else {
                 // Redirect to the role page
                 return redirect('admin/roles/' . $role->id . '/edit')->withInput()->withErrors($validator->messages());
             }
         }
     }
     $role->perms()->sync($this->permission->preparePermissionsForSave($request->input('permissions')));
     $role->is_protected = $request->has('is_protected') ? 1 : 0;
     $role->is_superuser = $request->has('is_superuser') ? 1 : 0;
     $role->save();
     // Form validation failed
     return redirect('admin/roles/' . $role->id . '/edit');
 }
开发者ID:fetch404,项目名称:fetch404,代码行数:75,代码来源:AdminRolesController.php


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