0
votes

I'm getting a row form the table and try to update like this;

{
      $db_dw = \DB::connection('sqlsrvdw');
            $factAlarm= $db_dw->table('ALARM')->where([['AlarmId',$id],['MostRecentFlag',1]])->first();
            print_r($factAlarm);  --->This prints my row

     $this->updateFactAlarm($factAlarm);
-----------------
   } 


    private function updateFactAlarm($factAlarm){
        $factAlarm->AlarmActionDescription= request('ackNotes');
        $factAlarm->IsAcknowledged = 1;
        $factAlarm->update();

    }

I get following error

Call to undefined method stdClass::update()

Even if I use save() method I get same error

Call to undefined method stdClass::save()

What is wrong with my approach?

1
why are you not using simple query like DB::table('table_name')->where(----)->update([-----]); ?Sagar Gautam
@SagarGautam i did as you mentioned $factAlarm= $db_dw->table('hdsira.FACT_ALARM')->where([['AlarmId',$id],['MostRecentFlag',1]]) ->update([['AlarmActionDescription'=>request('ackNotes')],['IsAcknowledged'=>1]]); But getting Array to string conversion (SQL: update [hdsira].[FACT_ALARM] set [0] = RATHAAA, [1] = 1 where ([LegAlarmId] = 114383 and [MostCurrentFlag] = 1)) errorRatha
@SagarGautam can't I update two values together?Ratha
@SagarGautam my bad removed square bracket and works fineRatha
ha ha congrats anywaySagar Gautam

1 Answers

0
votes

update() or save() are methods that can be used on an Eloquent model, and $factAlarm is not one. You should define the Alarm model and use Eloquent to query the table. Also please follow the naming conventions stated in the docs.