looks like you have TWO distinct many to many.. or are you looking to relate job/payments?
Mar 15, 2018
14
Level 9
Database Structure - 3 Models - Many to Many
3 Models are there
- Job
- Invoice
- Payment
Relationships between these are as below
Job and Invoice - Many to Many
jobs table
invoices table
invoice_job table
Invoice and Payment - Many to Many
invoices table
payments table
invoice_payment table
I need to access payment records through jobs Job and Payment will have a many to many relationship based on the other 2 models(Invoice and Payment)
@foreach ($jobs as $job)
@foreach ($job->payments as $payment)
<tr>
<td><a href="{{ route('job.edit',$job->id) }}">{{ $payment->pivot->job_id }}</a></td>
<td>{{ $payment->payment_no }}</td>
<td>{{ $payment->payment_date }}</td>
<td>{{ $payment->payment_amount }}</td>
<td>{{ $job->job_status }}</td>
</tr>
@endforeach
@endforeach
What kind of table structure should i have?
Should i maintain 3 tables for Jobs and Payments?
Can i use HasThrough for many to many?
Please or to participate in this conversation.