What is the best way to check if updated resource attributes have changed in afterSave hook?

I am currently doing this, but it seems inefficient and too verbose:
protected function afterSave(): void
{   
  $mealType = $this->record;
  $request = request()->all();
  $originalOrderDeadline = null;
  $updatedOrderDeadline = null;

  // Decode the JSON snapshot
  if (isset($request['components'][0]['snapshot'])) {
    $snapshot = json_decode($request['components'][0]['snapshot'], true);
  
    if (isset($snapshot['data']['data'])) {
      foreach ($snapshot['data']['data'] as $data) {
        if (isset($data['id']) && $data['id'] == $mealType->id) {
          $originalOrderDeadline = $data['order_deadline'];
          break;
        }
      }
    }
  }

  // Get the updated order_deadline
  if (isset($request['components'][0]['updates']['data.order_deadline'])) {
    $updatedOrderDeadline = $request['components'][0]['updates']['data.order_deadline'];
  }
}
Was this page helpful?