Hello,
I have three tables:
- Feeplan
- Student
- Invoice
Feeplan is linked with Student like below:
public function studentName()
{
return $this->belongsTo(Student::class);
}
Feeplan is linked with Invoice like below:
public function studentInvoices()
{
return $this->belongsToMany(Invoice::class);
}
Invoice is linked with Student like below:
public function studentName()
{
return $this->belongsToMany(Student::class);
}
Invoice is linked with Feeplan like below:
public function studentFee()
{
return $this->belongsToMany(Feeplan::class);
}
On Invoice Create Page, I use Select2 to select multiple students and show it on Invoice Show Page like this:
<td>
@foreach($invoice->studentName as $key => $entry)
<li><span>{{ $entry->student_name }}</span></li>
@endforeach
</td>
However, for amount, when I do the below, it ONLY gives one student's invoice amount (NOT for all selected student):
<td>
@foreach($invoice->studentFee as $key => $entry)
<li><span>{{ $entry->student_fee }}</span></li>
@endforeach
</td>
So if I can choose mutiple students in Select2, how can I show their fee in the amount column using above relations?
Many thanks