本文整理汇总了PHP中Permission::preparePermissionsForSave方法的典型用法代码示例。如果您正苦于以下问题:PHP Permission::preparePermissionsForSave方法的具体用法?PHP Permission::preparePermissionsForSave怎么用?PHP Permission::preparePermissionsForSave使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Permission
的用法示例。
在下文中一共展示了Permission::preparePermissionsForSave方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update
/**
* Update the specified resource in storage.
*
* @param $role
* @return Response
*/
public function update($role)
{
// If the 'admin' role is being updated, the name of this role will have been
// disabled in the form, and so won't be present in the form POST values.
// We'll change the rules here accordingly. The admin role cannot be renamed
// or deleted.
if ($role->name == 'admin') {
$rules = array('description' => 'required');
} else {
$rules = array('name' => 'required|alpha_dash|unique:roles,name,' . $role->id, 'description' => 'required');
}
// Validate the inputs
$validator = Validator::make(Input::all(), $rules);
// Check if the form validates with success
if ($validator->passes()) {
// Update the role data
if ($role->name != 'admin') {
$role->name = Input::get('name');
}
$role->description = Input::get('description');
$role->perms()->sync($this->permission->preparePermissionsForSave(Input::get('permissions')));
// Was the role updated?
if ($role->save($rules)) {
// Redirect to the role page
return Redirect::to('admin/roles/' . $role->id . '/edit')->with('success', Lang::get('admin/role/messages.update.success'));
} else {
// Redirect to the role page
return Redirect::to('admin/roles/' . $role->id . '/edit')->with('error', Lang::get('admin/role/messages.update.error'));
}
} else {
// Form validation failed
return Redirect::to('admin/roles/' . $role->id . '/edit')->withInput()->withErrors($validator);
}
}
示例2: postEdit
/**
* Update the specified resource in storage.
*
* @param $role
* @return Response
*/
public function postEdit($role)
{
$rules = array('name' => 'required');
$validator = Validator::make(Input::all(), $rules);
if ($validator->passes()) {
$role->name = Input::get('name');
$role->perms()->sync($this->permission->preparePermissionsForSave(Input::get('permissions')));
if ($role->save()) {
return Redirect::to('admin/roles/' . $role->id . '/edit')->with('success', Lang::get('admin/roles/messages.update.success'));
} else {
return Redirect::to('admin/roles/' . $role->id . '/edit')->with('error', Lang::get('admin/roles/messages.update.error'));
}
}
return Redirect::to('admin/roles/' . $role->id . '/edit')->withInput()->withErrors($validator);
}
示例3: putEdit
/**
* Update the specified resource in storage.
*
* @param $role
* @return Response
*/
public function putEdit($role)
{
// Declare the rules for the form validation
$rules = array('name' => 'required');
if (in_array(Input::old('name', $role->name), $this->protected_roles) && Input::old('name', $role->name) != Input::get('name') || in_array(Input::get('name'), $this->protected_roles) && Input::old('name', $role->name) != Input::get('name')) {
return Api::to(array('error', Lang::get('admin/roles/messages.update.error'))) ?: Redirect::to('admin/roles/' . $role->id . '/edit')->with('error', Lang::get('admin/roles/messages.update.error'));
}
// Validate the inputs
$validator = Validator::make(Input::all(), $rules);
// Check if the form validates with success
if ($validator->passes()) {
$role->name = Input::get('name');
$role->perms()->sync($this->permission->preparePermissionsForSave(Input::get('permissions')));
if ($role->save()) {
return Api::to(array('success', Lang::get('admin/roles/messages.update.success'))) ?: Redirect::to('admin/roles/' . $role->id . '/edit')->with('success', Lang::get('admin/roles/messages.update.success'));
} else {
return Api::to(array('error', Lang::get('admin/roles/messages.update.error'))) ?: Redirect::to('admin/roles/' . $role->id . '/edit')->with('error', Lang::get('admin/roles/messages.update.error'));
}
}
// Form validation failed
return Api::to(array('error', Lang::get('admin/roles/messages.update.error'))) ?: Redirect::to('admin/roles/' . $role->id . '/edit')->withInput()->withErrors($validator);
}