public function update($id)
    {
        $success = false;
        $message = '';
        $user    = null;
        $code    = 0;

        try{
            $input = Input::put();
            /** in case request come from post http form */
            $input = is_null($input) ? Input::post() : $input;

            if($input['password'] != $input['confirm_password']){
                throw new Exception("Password and confirmation password not match", 1);
            }

            $user = Sentry::findUserById($id);

            $user->email        = $input['email'];
            $user->first_name   = $input['first_name'];
            $user->last_name    = $input['last_name'];

            if($input['password']){
                $user->password = $input['password'];
            }

            $success = $user->save();
            $code    = 200;
            $message = 'User updated sucessully';
        }catch(UserNotFoundException $e){
            $message = $e->getMessage();
            $code    = 404;
        }catch (Exception $e){
            $message = $e->getMessage();
            $code    = 500;
        }

        if(Request::isAjax()){
            Response::headers()->set('Content-Type', 'application/json');
            Response::setBody(json_encode(
                array(
                    'success'   => $success,
                    'data'      => ($user) ? $user->toArray() : $user,
                    'message'   => $message,
                    'code'      => $code
                )
            ));
        }else{
            Response::redirect($this->siteUrl('admin/user/'.$id.'/edit'));
        }
    }
public function update($id)
    {
        $success = false;
        $message = '';
        $user    = null;
        $code    = 0;

        try{
            $input = Input::put();
            /** in case request come from post http form */
            $input = is_null($input) ? Input::post() : $input;

            if($input['password'] != $input['confirm_password']){
                throw new Exception("Password and confirmation password not match", 1);
            }

            $user = Sentry::findUserById($id);

            $user->email        = $input['email'];
            $user->first_name   = $input['first_name'];
            $user->last_name    = $input['last_name'];

            if($input['password']){
                $user->password = $input['password'];
            }

            $success = $user->save();
            $code    = 200;
            $message = 'User updated sucessully';
        }catch(UserNotFoundException $e){
            $message = $e->getMessage();
            $code    = 404;
        }catch (Exception $e){
            $message = $e->getMessage();
            $code    = 500;
        }

        if(Request::isAjax()){
            Response::headers()->set('Content-Type', 'application/json');
            Response::setBody(json_encode(
                array(
                    'success'   => $success,
                    'data'      => ($user) ? $user->toArray() : $user,
                    'message'   => $message,
                    'code'      => $code
                )
            ));
        }else{
            Response::redirect($this->siteUrl('admin/user/'.$id.'/edit'));
        }
    }
public function update ( $ id ) { $ success = false ; $ message = '' ; $ user = null ; $ code = 0 ; try { $ input = Input :: put ( ) ; /** in case request come from post http form */ $ input = is_null ( $ input ) ? Input :: post ( ) : $ input ; if ( $ input [ 'password' ] != $ input [ 'confirm_password' ] ) { throw new Exception ( "Password and confirmation password not match" , 1 ) ; } $ user = Sentry :: findUserById ( $ id ) ; $ user -> email = $ input [ 'email' ] ; $ user -> first_name = $ input [ 'first_name' ] ; $ user -> last_name = $ input [ 'last_name' ] ; if ( $ input [ 'password' ] ) { $ user -> password = $ input [ 'password' ] ; } $ success = $ user -> save ( ) ; $ code = 200 ; $ message = 'User updated sucessully' ; } catch ( UserNotFoundException $ e ) { $ message = $ e -> getMessage ( ) ; $ code = 404 ; } catch ( Exception $ e ) { $ message = $ e -> getMessage ( ) ; $ code = 500 ; } if ( Request :: isAjax ( ) ) { Response :: headers ( ) -> set ( 'Content-Type' , 'application/json' ) ; Response :: setBody ( json_encode ( array ( 'success' => $ success , 'data' => ( $ user ) ? $ user -> toArray ( ) : $ user , 'message' => $ message , 'code' => $ code ) ) ) ; } else { Response :: redirect ( $ this -> siteUrl ( 'admin/user/' . $ id . '/edit' ) ) ; } }
update resource with specific id
update resource with specific id