Database Structure - 3 Models - Many to Many

Posted 10 months ago by zaster

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)
                    <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>

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 sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.