I have four tables.
customer_billing_header
id | customer_id | due_date
1 | 1 | 2016-01-01
customer_billing_details
id | header_id | bill_item_id
1 | 1 | 1
2 | 1 | 2
3 | 1 | 3
customer_bill_items
id | name
1 | CCTV
2 | Mouse
3 | Keyboard
customer_monthly_bill
id | customer_id | bill_item_id
1 | 1 | 1
Now, I want to get the header and load the other three tables. I'm able to load only customer_billing_details. I don't know how to connect the customer_bill_items and customer_monthly_bill.
In my customer_billing_header model:
public function customer_billing_detail() {
return $this->hasMany('App\Customer_Billing_Details', 'header_id');
}
In my controller:
public function show($id) {
$headers = Customer_Billing_Header::where('customer_id', $id)->get();
$headers->load('customer_billing_detail');
return $headers;
}
I want to make like:
public function show($id) {
$headers = Customer_Billing_Header::where('customer_id', $id)->get();
$headers->load('customer_billing_detail', 'customer_bill_item', 'customer_monthly_bill');
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire