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