Question: I have 3 Models connected this way:

`Organization` → `ApplicationInstance` →(Pivot)→ `Invoice`

**Any idea how to get all Invoices from the Organization?**

Answer: 
If you have defined the [relationships](https://laravel.com/docs/5.7/eloquent-relationships#defining-relationships) on your models, then you can use `$organization->application_instance->invoice`.
This is my solution to this problem:

```
    public function invoices() {

    $indexes = \DB::select('SELECT invoices.id FROM invoices,application_instance_invoice,application_instances
    WHERE invoices.id=application_instance_invoice.invoice_id
    AND application_instances.id=application_instance_invoice.application_instance_id
    AND application_instances.organization_id=:id', ['id' => $this->id]);

    $indexArray = array();

    foreach($indexes as $index) {
        array_push($indexArray,$index->id);
    }

    return Invoice::whereIn('id', $indexArray)->orderBy('created_at');
}

```

I am pretty sure there are easier ways to do this but this does the trick.