简体   繁体   中英

My ELSE condition refuses to run in IF/ELSE Laravel

I have a basic if/else statement is Laravel.

$model = MyModel::where('row', 'abc123')->first();

// Returns 3 statuses - connected, inactive, disconnected
$status = getStatus();

if ($status === 'connected') {
   if (!$model->is_active) {
       $model->timed_at = now();
   }

   $model->is_active = true;
}
else {
   if ($model->is_active) {
       $model->last_timed_at = $model->updated_at;
   }

   $model->is_active = false;
}

$model->save();

NOTE: This function is called repeatedly at an interval of 10 seconds.

The ELSE functionality works flawlessly outside the ELSE statement.

But the moment it's in the ELSE, it doesn't run at all. I have proven that it does reach the ELSE by adding an echo which works fine.

Another odd thing, when I place the ELSE in the IF side, it works perfectly fine.

Thanks everyone for the input. Turns out the data I was tweaking during my testing gave me unexpected (they were actually expected) results.

Not sure how to fully close a question, but leaving this here to say it was a non-issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM