F
F
freelancer0072018-03-21 12:05:15
MySQL
freelancer007, 2018-03-21 12:05:15

How to correctly implement a request in Laravel?

Good day everyone!
There is a Report model, you need to get the data so that they are sorted (or grouped) by month, the sorting field is `created_at` type timestamp.
I will try to explain the task itself in a little more detail, there is a site.ru/report/january route, when you go, a list of models added in January opens.
Using sql, this can be done using MONTH
ORDER BY MONTH(created_at) ASC
How to implement this using Laravel Eloquent ORM?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Mashletov, 2018-03-21
@freelancer007

Report::orderByRaw('MONTH(created_at) ASC')->get()

Report::whereRaw("'MONTH(created_at) = 1")->orderBy('created_at')->get()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question