I have this query:
public function payment($id = "", $slug = "", $regID)
{
$registrationTypeDetails = Registration::with(['participants.registration_type',
'participants' => function ($query) use ($regID) {
$query->select('id', 'registration_type_id', 'registration_id')->where('registration_id', $regID);
}
])->find($regID);
return view('conferences.showSummary', compact( 'registrationTypeDetails'));
}
To get the info(name and price) about each registration type where each participant is registered in a specific conference registration. (A registration has some participants and each participant is associated with a registration type.)
So $registrationTypeDetails shows:
Registration {#259 ▼
...
#relations: array:1 [▼
"participants" => Collection {#263 ▼
#items: array:2 [▼
0 => Participant {#270 ▼
...
#relations: array:1 [▼
"registration_type" => RegistrationType {#276 ▼
....
#attributes: array:12 [▼
"id" => 2
"name" => "free"
"price" => 0
"conference_id" => 2
]
...
}
]
...
}
1 => Participant {#272 ▼
...
#relations: array:1 [▼
"registration_type" => RegistrationType {#278 ▼
...
#attributes: array:12 [▼
"id" => 3
"name" => "paid"
"price" => 1
"conference_id," => 2
]
...
}
]
}
]
}
]
...
}
With this query results I want to show in the view the registration type name, price, quantity and subtotal. The name and price is already working with the code below.
Doubt: But do you know how to get the quantity and subtotal of each registration type? For example if the registration is composed of 3 participants, 2 participants registered in the registration type "general" and 1 in the registration type "plus" I want to show the quantity 2 for the registration type "general" and quantity 1 for the registration type "plus", like:
@foreach($registrationTypeDetails->participants as $participant)
<li class="list-group-item list-group-registration d-flex align-items-center justify-content-between">
<span class="font-size-sm"> {{$participant->registration_type['name']}} </span>
<span class="font-size-sm">{{$participant->registration_type['price']}} </span>
<!--<span class="font-size-sm">how to show the quantity? (ex: 2) </span>-->
<!--<span class="font-size-sm">how to show the subtotal? (ex: 4$)</span>-->
</li>
@endforeach