@php use App\User; use App\Plan; use App\BusinessCard; use Carbon\Carbon; // Card details $business_card = BusinessCard::where('card_id', Request::segment(3))->first(); // Fetch the user plan $plan = User::where('user_id', Auth::user()->user_id)->first(); $active_plan = json_decode($plan->plan_details, true); if ($active_plan) { // Fetch the default plan details only once if necessary if (!$active_plan || !isset($active_plan['appointment'])) { $planDefaults = Plan::where('plan_id', $plan->plan_id)->first(); } // Check and assign missing plan details $active_plan['appointment'] = $active_plan['appointment'] ?? $planDefaults->appointment; // Update plan details if necessary if ($active_plan !== json_decode($plan->plan_details, true)) { $plan->plan_details = json_encode($active_plan); $plan->updated_at = Carbon::now(); $plan->save(); } // Fetch the updated plan details $active_plan = json_decode($plan->plan_details, true); } @endphp