Skip to content
Advertisement

How to get user order data by specific month in laravel?

I want to user orders data by specific month in a year.

Here is my order Table

id | user_id | price | quantity | total

Here is my order model

JavaScript

Here is my user model

JavaScript

In a controller, by doing this I get all user orders

JavaScript

Now, How can I get specific month user orders detail? I want to show all user list with their order’s total amount by month.

Advertisement

Answer

Try this to get users with their orders’ total of September:

JavaScript

This will place a september_total attribute on your resulting models.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement