/**
  * Store a newly created resource in storage.
  *
  * @param  UserRequest $request
  * @return Response
  */
 public function store(UserRequest $request)
 {
     $User = new User();
     $User->name = $request->get('name');
     $User->email = $request->get('email');
     $User->password = bcrypt($request->get('password'));
     if ($User->save()) {
         return Redirect::route('back.system.users.index')->with('message', 'Successfully created record!')->with('message-class', 'success');
     } else {
         return Redirect::route('back.system.users.create')->with('message', 'Whooops! Could not create the record.')->with('message-class', 'error')->withInputs();
     }
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  UserRequest $request
  * @param  int $id
  * @return Response
  */
 public function update(UserRequest $request, $id)
 {
     $User = User::find($id);
     $User->name = $request->get('name');
     $User->email = $request->get('email');
     if ($request->get('password') && env('APP_ENV') != 'homolog') {
         $User->password = bcrypt($request->get('password'));
     }
     if ($User->save()) {
         return Redirect::route('back.system.users.index')->with('message', 'Successfully updated record!')->with('message-class', 'success');
     } else {
         return Redirect::route('back.system.users.edit')->with('message', 'Whooops! Could not update the record.')->with('message-class', 'error')->withInputs();
     }
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  UserRequest $request
  * @param  int $id
  * @return Response
  */
 public function update(UserRequest $request, $id)
 {
     $User = User::find($id);
     $User->name = $request->get('name');
     $User->email = $request->get('email');
     $User->password = bcrypt($request->get('password'));
     if (Gate::denies('update', $User)) {
         return Redirect::route('back.system.users.index')->with('message', 'Not Allowed!')->with('message-class', 'danger');
     } else {
         if ($User->save()) {
             return Redirect::route('back.system.users.index')->with('message', 'Successfully created record!')->with('message-class', 'success');
         } else {
             return Redirect::route('back.system.users.create')->with('message', 'Whooops! Could not create the record.')->with('message-class', 'error')->withInputs();
         }
     }
 }