Needed Help for Query
This is my Seller Table.I need to find all sales from seller id 1
id | name | phone |
1 | Coder | 98653271039 |
This is my Sales table
id | action_date | seller_id | quantity | product_id |
1 | 2021-01-01 | 1 | 50 | 1 |
2 | 2021-01-01 | 1 | 100 | 2 |
3 | 2021-01-01 | 1 | 150 | 2 |
4 | 2021-01-03 | 1 | 120 | 1 |
5 | 2021-01-04 | 1 | 190 | 1 |
This is my product table
id | name |
1 | Mobile |
2 | Laptop |
This is my Sale.php
public function product()
{
return $this->belongsTo('App\Product');
}
public function seller()
{
return $this->belongsTo('App\Seller', 'seller_id');
}
I want my result like this.I want to query to be sum all quantity of each day of each product .
| Date | Mobile | Laptop |
| Sales | Stock | Sales | Stock |
2021-01-01| 50 | 0 | 250 | 0
2021-01-03| 120 | 0 | 0 | 0
2021-01-04| 190 | 0 | 0 | 0
For sales by seller 1
$sales = Sale::where('seller_id', 1)->get();
For sales by each seller
$sales = Sale::all()->groupBy('seller_id');
For sum of all quantity of each day of each product
$sales = Sale::all()->groupBy('action_date')->groupBy('product_id')->sum('quantity');
Yes but how can i display that in blade file in table exactly above ?
Please or to participate in this conversation.