vendredi 23 juin 2017

How to get multiple joined data in one Laravel DB Function

I have the following ERD:

My ERD

Now what i want to do is get Facturatie_Route_Manager with:

Facturatie_Invoice
Facturatie_Customer
Facturatie_Invoice_Line
Facturatie_Product

Now when i try the following:

public function loadRouteData($day, $week_nr, $year){
    $route_data = DB::table('facturatie_route_manager')
    ->join('facturatie_invoice', 'facturatie_route_manager.invoice_id','=','facturatie_invoice.id')
    ->join('facturatie_customer', 'facturatie_invoice.customer_id','=','facturatie_customer.id')
    ->where(['facturatie_invoice.day' => $day,
             'facturatie_route_manager.week_nr' => $week_nr,
             'facturatie_route_manager.year' => $year])
    ->get();
    return $route_data;
}

I get duplicate records for route manager because each new invoice line don't get added to the same record but makes a new record instead. Also because i don't get the desired result i'm not including Facturatie_Product here yet.

Any ideas? I'm using Laravel 5+.

I've tried using models from Facturatie_Route_Manager but can't seem to refer Facturatie_Invoice id to Facturatie_Invoice_Line invoice_id starting at model Facturatie_Route_Manager. I would prefer not using joins if possible.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2tVQXnl
via IFTTT

Aucun commentaire:

Enregistrer un commentaire