Kindly see below my table structure
**products** id code 1 code_1 2 code_2 3 code_3 4 code_4 **sales** id invoice 1 inv_1 2 inv_2 **sales_details** id sales_id product_id sales_qty 1 1 1 10 2 1 2 5 3 2 2 6 4 2 3 1
I want a display like this:
invoice code_1 code_2 code_3 code_4(so on and so forth) inv1 10 5 0 0 inv2 1 6 1 0
These are the sample values for a better view of the desired output. Thank you!
Advertisement
Answer
invoice code_1 code_2 code_3 code_4(so on and so forth)
It is not a good idea to print details vertically because it will not be the same in all invoices, also may it will be so long.
I suggest to change your structure to:
Invoice ID | Client | Employee | Total | Settings 1 | Client | Employee | 144 | Show – Edit – Delete
and in the show page you can print the details, or show it in a popup.
At all you can print it at any structure you want you just get all invoices and loop to print the invoice and get items from the invoice and inner loop to print them.
- Model structure will be like:
// Invoice
class Invoice extends model { public function items() { return $this->hasMany(Item::class); } }
// Item
class Item extends model { public function invoice() { return $this->belongTo(Invoice::class); } public function product() { return $this->belongTo(Product::class); } }
— Note: I replace ‘sales’ with ‘invoices’