0

I am trying to save an api call to my databases. but I am getting an error while saving to the databases

I search google and look here. I have tried the code that was offered I have not had much luck.

public function updateCalendarIfNeeded($calendarentrydata)
{
            foreach($calendarentrydata as $titan)
            {
                $summary = $titan->summary;
                $id = $titan->id;
                $fileurl = $titan['attachments']['0']['fileUrl'];
                $startdate = $titan->start->datetime;
                $enddate = $titan->end->datetime;

           $calendarpullerEntryNew = CalendarEvents::findOne([
            'calendar_id' => $id
        ]);
        if (!empty($calendarpullerEntryNew)) {
            $calendarEvents = $calendarpullerEntryNew;
        }

        // now update entry if Calendar info found
        $calendarEvents->calendar_id = $id;
        $calendarEvents->calendar_summary = $summary;
        $calendarEvents->calendar_start = $startdate;
        $calendarEvents->calendar_end = $enddate;
        $calendarEvents->file_link = $fileurl;


        if (empty($calendarEvents->id)) {
            $calendarEvents->save();
        } else {
            $calendarEvents->update();
        }
            }
    return $calendarPullerEntry;
}

I am getting undefined method stdClass::save(). if I am not mistaking I am using Yii framework to do the save I have not used it before so I am lost

i did a var_dump on my variable and an stdclass here is the debug stdClass Object ( [calendar_id] => 1hj1o20jc6ucli4st6rk60rfic [calendar_summary] => seeing if php loves me [calendar_start] => [calendar_end] => [file_link] => https://drive.google.com/file/d/1AOPdiXtmz8oNrV2uoSNjLcLso5JdU8CM/view?usp

Semesic
  • 39
  • 1
  • 5

1 Answers1

0

Everyone Here needs to roast me. I am the stupidest person on the planet lol. I forgot to call the Function that put the ActiveRecord my code should have look like this

        // now update entry if Calendar info found
        $calendarEvents = new CalendarEvents();
        $calendarEvents->calendar_id = $id;
        $calendarEvents->calendar_summary = isset($summary) ? $summary : '';
        $calendarEvents->calendar_start = $startdate;
        $calendarEvents->calendar_end = $enddate;
        $calendarEvents->file_link = $fileurl;


        if (empty($calendarEvents->id)) {
            $calendarEvents->save();
        } else {
            $calendarEvents->update();
        }

In my case, I will call the function and delete the new CalendarEntry but that was my problem sorry for any who wasted there time reading this lol

Semesic
  • 39
  • 1
  • 5