Laravel 5, Call to undefined method stdClass::update()










0















I'm using Laravel 5 and I have a simple edit page that must update database. when I try to run it, I got error




FatalErrorException in UserController.php line 47: Call to undefined method stdClass::update()




Controller :



public function userUpdate()

if(Input::get('send'))
$arr = [
'email' => Input::get('email')
];
DB::table(Config::get('users_table'))->find(Input::get('userId'))->update(['is_active' => TRUE]);
return redirect()->route('users');




Database schema :



id bigserial NOT NULL,
username text,
email text,
permission integer NOT NULL,
is_staff boolean NOT NULL DEFAULT false,
is_active boolean NOT NULL DEFAULT false,
updated_at timestamp without time zone,
created_at timestamp without time zone,
remember_token text


Route :



Route::post('/user/update', [
'as' => 'userUpdate', 'uses' => 'UserController@userUpdate'
]);


View :



!! Form::open(['route' => 'userUpdate', 'method' => 'post']) !!

<label>Username</label>
!! Form::text('username', $user->username, ['class' => 'form-control readonly', 'readonly' => '']) !!

<label>Email</label>
!! Form::text('email', $user->email, ['class' => 'form-control']) !!

<label>Permission</label>
!! Form::text('permission', $user->permission, ['class' => 'form-control']) !!

!! Form::hidden('userId', $user->id) !!
!! Form::submit('Update User', ['class' => 'btn green', 'name' => 'send']) !!
!! Form::submit('Cancel', ['class' => 'btn black', 'name' => 'clear']) !!
!! Form::close() !!


I use this structure, specially this type of using Input and Form class in another function in my controller for make list of rows or get an individual row of table, and everything was ok, but in updating database I got Call to undefined method stdClass::update() error. Is there something that I am missing?










share|improve this question


























    0















    I'm using Laravel 5 and I have a simple edit page that must update database. when I try to run it, I got error




    FatalErrorException in UserController.php line 47: Call to undefined method stdClass::update()




    Controller :



    public function userUpdate()

    if(Input::get('send'))
    $arr = [
    'email' => Input::get('email')
    ];
    DB::table(Config::get('users_table'))->find(Input::get('userId'))->update(['is_active' => TRUE]);
    return redirect()->route('users');




    Database schema :



    id bigserial NOT NULL,
    username text,
    email text,
    permission integer NOT NULL,
    is_staff boolean NOT NULL DEFAULT false,
    is_active boolean NOT NULL DEFAULT false,
    updated_at timestamp without time zone,
    created_at timestamp without time zone,
    remember_token text


    Route :



    Route::post('/user/update', [
    'as' => 'userUpdate', 'uses' => 'UserController@userUpdate'
    ]);


    View :



    !! Form::open(['route' => 'userUpdate', 'method' => 'post']) !!

    <label>Username</label>
    !! Form::text('username', $user->username, ['class' => 'form-control readonly', 'readonly' => '']) !!

    <label>Email</label>
    !! Form::text('email', $user->email, ['class' => 'form-control']) !!

    <label>Permission</label>
    !! Form::text('permission', $user->permission, ['class' => 'form-control']) !!

    !! Form::hidden('userId', $user->id) !!
    !! Form::submit('Update User', ['class' => 'btn green', 'name' => 'send']) !!
    !! Form::submit('Cancel', ['class' => 'btn black', 'name' => 'clear']) !!
    !! Form::close() !!


    I use this structure, specially this type of using Input and Form class in another function in my controller for make list of rows or get an individual row of table, and everything was ok, but in updating database I got Call to undefined method stdClass::update() error. Is there something that I am missing?










    share|improve this question
























      0












      0








      0








      I'm using Laravel 5 and I have a simple edit page that must update database. when I try to run it, I got error




      FatalErrorException in UserController.php line 47: Call to undefined method stdClass::update()




      Controller :



      public function userUpdate()

      if(Input::get('send'))
      $arr = [
      'email' => Input::get('email')
      ];
      DB::table(Config::get('users_table'))->find(Input::get('userId'))->update(['is_active' => TRUE]);
      return redirect()->route('users');




      Database schema :



      id bigserial NOT NULL,
      username text,
      email text,
      permission integer NOT NULL,
      is_staff boolean NOT NULL DEFAULT false,
      is_active boolean NOT NULL DEFAULT false,
      updated_at timestamp without time zone,
      created_at timestamp without time zone,
      remember_token text


      Route :



      Route::post('/user/update', [
      'as' => 'userUpdate', 'uses' => 'UserController@userUpdate'
      ]);


      View :



      !! Form::open(['route' => 'userUpdate', 'method' => 'post']) !!

      <label>Username</label>
      !! Form::text('username', $user->username, ['class' => 'form-control readonly', 'readonly' => '']) !!

      <label>Email</label>
      !! Form::text('email', $user->email, ['class' => 'form-control']) !!

      <label>Permission</label>
      !! Form::text('permission', $user->permission, ['class' => 'form-control']) !!

      !! Form::hidden('userId', $user->id) !!
      !! Form::submit('Update User', ['class' => 'btn green', 'name' => 'send']) !!
      !! Form::submit('Cancel', ['class' => 'btn black', 'name' => 'clear']) !!
      !! Form::close() !!


      I use this structure, specially this type of using Input and Form class in another function in my controller for make list of rows or get an individual row of table, and everything was ok, but in updating database I got Call to undefined method stdClass::update() error. Is there something that I am missing?










      share|improve this question














      I'm using Laravel 5 and I have a simple edit page that must update database. when I try to run it, I got error




      FatalErrorException in UserController.php line 47: Call to undefined method stdClass::update()




      Controller :



      public function userUpdate()

      if(Input::get('send'))
      $arr = [
      'email' => Input::get('email')
      ];
      DB::table(Config::get('users_table'))->find(Input::get('userId'))->update(['is_active' => TRUE]);
      return redirect()->route('users');




      Database schema :



      id bigserial NOT NULL,
      username text,
      email text,
      permission integer NOT NULL,
      is_staff boolean NOT NULL DEFAULT false,
      is_active boolean NOT NULL DEFAULT false,
      updated_at timestamp without time zone,
      created_at timestamp without time zone,
      remember_token text


      Route :



      Route::post('/user/update', [
      'as' => 'userUpdate', 'uses' => 'UserController@userUpdate'
      ]);


      View :



      !! Form::open(['route' => 'userUpdate', 'method' => 'post']) !!

      <label>Username</label>
      !! Form::text('username', $user->username, ['class' => 'form-control readonly', 'readonly' => '']) !!

      <label>Email</label>
      !! Form::text('email', $user->email, ['class' => 'form-control']) !!

      <label>Permission</label>
      !! Form::text('permission', $user->permission, ['class' => 'form-control']) !!

      !! Form::hidden('userId', $user->id) !!
      !! Form::submit('Update User', ['class' => 'btn green', 'name' => 'send']) !!
      !! Form::submit('Cancel', ['class' => 'btn black', 'name' => 'clear']) !!
      !! Form::close() !!


      I use this structure, specially this type of using Input and Form class in another function in my controller for make list of rows or get an individual row of table, and everything was ok, but in updating database I got Call to undefined method stdClass::update() error. Is there something that I am missing?







      php laravel laravel-5 stdclass laravel-query-builder






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 2 '16 at 6:36









      Mahmood KohansalMahmood Kohansal

      557524




      557524






















          2 Answers
          2






          active

          oldest

          votes


















          3














          you can't use find method in query builder,you need to use where



          public function userUpdate()

          if(Input::get('send'))
          $arr = [
          'email' => Input::get('email')
          ];
          DB::table(Config::get('users_table'))->where('id',Input::get('userId'))->update(['is_active' => TRUE]);
          return redirect()->route('users');







          share|improve this answer






























            1














            In my case I had to change from



            first() to limit(1)


            ie.



             $blog = DB::table('blogs')
            ->where('blogs.id', $id)
            ->first();


            To



             $blog = DB::table('blogs')
            ->where('blogs.id', $id)
            ->limit(1);





            share|improve this answer






















              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f35146650%2flaravel-5-call-to-undefined-method-stdclassupdate%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              3














              you can't use find method in query builder,you need to use where



              public function userUpdate()

              if(Input::get('send'))
              $arr = [
              'email' => Input::get('email')
              ];
              DB::table(Config::get('users_table'))->where('id',Input::get('userId'))->update(['is_active' => TRUE]);
              return redirect()->route('users');







              share|improve this answer



























                3














                you can't use find method in query builder,you need to use where



                public function userUpdate()

                if(Input::get('send'))
                $arr = [
                'email' => Input::get('email')
                ];
                DB::table(Config::get('users_table'))->where('id',Input::get('userId'))->update(['is_active' => TRUE]);
                return redirect()->route('users');







                share|improve this answer

























                  3












                  3








                  3







                  you can't use find method in query builder,you need to use where



                  public function userUpdate()

                  if(Input::get('send'))
                  $arr = [
                  'email' => Input::get('email')
                  ];
                  DB::table(Config::get('users_table'))->where('id',Input::get('userId'))->update(['is_active' => TRUE]);
                  return redirect()->route('users');







                  share|improve this answer













                  you can't use find method in query builder,you need to use where



                  public function userUpdate()

                  if(Input::get('send'))
                  $arr = [
                  'email' => Input::get('email')
                  ];
                  DB::table(Config::get('users_table'))->where('id',Input::get('userId'))->update(['is_active' => TRUE]);
                  return redirect()->route('users');








                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Feb 2 '16 at 6:41









                  Imtiaz PabelImtiaz Pabel

                  3,6601816




                  3,6601816























                      1














                      In my case I had to change from



                      first() to limit(1)


                      ie.



                       $blog = DB::table('blogs')
                      ->where('blogs.id', $id)
                      ->first();


                      To



                       $blog = DB::table('blogs')
                      ->where('blogs.id', $id)
                      ->limit(1);





                      share|improve this answer



























                        1














                        In my case I had to change from



                        first() to limit(1)


                        ie.



                         $blog = DB::table('blogs')
                        ->where('blogs.id', $id)
                        ->first();


                        To



                         $blog = DB::table('blogs')
                        ->where('blogs.id', $id)
                        ->limit(1);





                        share|improve this answer

























                          1












                          1








                          1







                          In my case I had to change from



                          first() to limit(1)


                          ie.



                           $blog = DB::table('blogs')
                          ->where('blogs.id', $id)
                          ->first();


                          To



                           $blog = DB::table('blogs')
                          ->where('blogs.id', $id)
                          ->limit(1);





                          share|improve this answer













                          In my case I had to change from



                          first() to limit(1)


                          ie.



                           $blog = DB::table('blogs')
                          ->where('blogs.id', $id)
                          ->first();


                          To



                           $blog = DB::table('blogs')
                          ->where('blogs.id', $id)
                          ->limit(1);






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 14 '18 at 18:20









                          Black MambaBlack Mamba

                          2,81412139




                          2,81412139



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f35146650%2flaravel-5-call-to-undefined-method-stdclassupdate%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Top Tejano songwriter Luis Silva dead of heart attack at 64

                              政党

                              天津地下鉄3号線