Conveyance

@if(count($itenary->additional_conveyances)>0) Item Type Actual Price ({{ $itenary->currencycode }} ) @php // Get an array of conveyance IDs, conveyance type IDs, and their actual prices from the backend function $conveyanceData = $conveyanceIds; // Convert conveyanceData to a more usable structure by combining conveyances_id and conveyance_type_id as a composite key $conveyanceArray = collect($conveyanceData)->keyBy(function($item) { return $item['conveyances_id'] . '-' . $item['conveyance_type_id']; }); @endphp @foreach($itenary->additional_conveyances as $conveyance) @php // Create a composite key based on conveyance id and conveyance type id /*$compositeKey = $conveyance['id'] . '-' . $conveyance['conveyance_type_id']; // Check if the composite key exists in the returned data $isSelected = $conveyanceArray->has($compositeKey); // Get the actual price if conveyance exists, otherwise set to 0 $actualPrice = $isSelected ? $conveyanceArray[$compositeKey]['actual_price'] : 0;*/ $isSelected = $itenary->conveyances->filter(function ($item) use ($conveyance) { return $item->conveyances_id == $conveyance['id'] && $item->conveyance_type_id == $conveyance['conveyance_type_id']; })->isNotEmpty(); /*$actualPrice = $isSelected ? $itenary->conveyances ->where('conveyances_id', $conveyance['id'])->firstWhere('conveyance_type_id', $conveyance['conveyance_type_id'])->actual_price : 0;*/ $actualPrice = $isSelected ? optional($itenary->conveyances->where('conveyances_id', $conveyance['id'])->firstWhere('conveyance_type_id', $conveyance['conveyance_type_id']))->actual_price : optional($itenary->conveyances()->withTrashed()->where('conveyances_id', $conveyance['id'])->firstWhere('conveyance_type_id',$conveyance['conveyance_type_id']))->actual_price ?? 0.00; @endphp {{ $conveyance['owner_name'] }} {{ $conveyance['conveyance_type_names'] }} @endforeach @else No Conveyance Found @endif