The reason you're not getting the results you want is because you're using where
instead of whereRaw
. In this case your query going to return:
select * from `projects` where end_date BETWEEN CURRENT_DATE() AND DATE_ADD(CURRENT_DATE(), INTERVAL 30 DAY) is null
(notice the is null
part).
To get the results you want change where
to whereRaw
(you can remove the DB::raw
):
project::whereRaw('end_date BETWEEN CURRENT_DATE() AND DATE_ADD(CURRENT_DATE(), INTERVAL 30 DAY)')->get();
Alternatively, you could use a mixture of whereBetween and Carbon:
project::whereBetween('end_date', [now(), now()->addDays(30)])->get();
Check out this answer for more information.