Building an array for a custom widget
Hello, trying for two days now to solve this.
What I need is to sum the quantity of items for orders with payment_status=1 and group them by format and build the widget array like this
[format][sum(quantity)]
9 Replies
please ask in the laravel server, since this is just a question about producing an array
ok, sorry
no need to be sorry
you will just probably get a quicker answer there
You'll need to use DB::Raw to sum as a select opposed to summing the whole query.
Thanks, it helped me a lot.
I'm close to something.
Started from OrderItem model this time.
Now I have my formats array.
Is it possible to sum(total_products) for each format (A4,A5) before the ->toArray?
No, you can run a map or a loop. Try:
Thanks, I'll try that later, for now I have used array_sum(array_column($order_f, 'total_products')) in blade.