Home > Net >  My ELSE condition refuses to run in IF/ELSE Laravel
My ELSE condition refuses to run in IF/ELSE Laravel

Time:09-21

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.

CodePudding user response:

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.

  • Related