Exemplo n.º 1
0
 /**
  * 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);
     }
 }
Exemplo n.º 2
0
 /**
  * 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);
 }
 /**
  * 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);
 }
 /**
  * Update the specified resource in storage.
  *
  * @param $role
  * @return Response
  */
 public function postEdit($role)
 {
     // Declare the rules for the form validation
     $rules = array('name' => 'required');
     // Validate the inputs
     $validator = Validator::make(Input::all(), $rules);
     // Check if the form validates with success
     if ($validator->passes()) {
         // Update the role data
         $role->name = Input::get('name');
         $role->perms()->sync($this->permission->preparePermissionsForSave(Input::get('permissions')));
         // Was the role updated?
         if ($role->save()) {
             // Redirect to the role page
             return Redirect::to('admin/roles/' . $role->id . '/edit')->with('success', Lang::get('admin/roles/messages.update.success'));
         } else {
             // Redirect to the role page
             return Redirect::to('admin/roles/' . $role->id . '/edit')->with('error', Lang::get('admin/roles/messages.update.error'));
         }
     }
     // Form validation failed
     return Redirect::to('admin/roles/' . $role->id . '/edit')->withInput()->withErrors($validator);
 }