D
D
Dmitry2016-09-18 14:02:22
Laravel
Dmitry, 2016-09-18 14:02:22

How to construct a query in laravel to select all news for a certain month?

It is necessary to extract from the database all published news of a certain category (for example, "second"). I do this with a simple query:

$data['news']=$news->where([
            ['category', '2'],
            ['published', '1']
        ])->get();

But this query needs to be improved so that there is a selection of news only for a certain month, for example, for September (09). I just can't figure out how to modify this line to make such a selection. If I wrote a query in pure SQL, I would use DATE_FORMAT, but here a record like
[date_format('date', '%m'), '09']
does not
work Please help me understand!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Evgeny Perin, 2016-09-18
@battrack

Try
whereMonth('date', '=', 9);

D
Dmitry Chekanov, 2016-09-18
@LanDer931

Kuri Carbon

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question