ordering dates

Published 11 months ago by dmcglone27

Hi all, I'm trying to get 3 dates, but I don't want any date that is more than 2 or 3 days in the past. For example I have Sept 29, 2016, Oct 15, 2017, Oct 16, 2017 and Oct 31, 2017.. All I want is the 15th, 16th and 31st of 2017 what could I do here to accomplish that? I have tried latest(), latest('date', 'asc') but neither work. Suggestions?

view()->composer('partials.events', function ($view) {

            $view->with('events', Events::orderBy('date)->where('archived', false)->limit(3)->get());


Try latest or oldest which orders by created_at column.



Doesn't it work for you?

$view->with('events', Events::orderBy('date', 'desc')->where('archived', false)->limit(3)->get());
11 months ago (999,845 XP)

you can only order if the column is datetime or timestamp. Is that true?


Thanks guys, after a long hiatus from Laravel, I forgot a few things, but seeing the examples , refreshed my memory and here is what worked for me.

view()->composer('partials.events', function ($view) {

            $view->with('events', Events::orderBy('date')->where('date', '>=', Carbon::today())->where('archived', false)->limit(3)->get());


Please sign in or create an account to participate in this conversation.