mardi 4 juillet 2017

laravel eloquent compare 2 dates against today

So I have events table which has start date and end date.

What I want to do is a comparison between today and start date + end date so if today is between start and end, return that collection which will be displayed on page, if it isn't ignore that event.

Problem is that when I retrieve an event I cannot access it as it is return that it doesn't exist in the collection, but it does after view is returned.

Here's my controller:

public function show($id)
{
    $today = date("Y-m-d");
    $today_dt = new DateTime($today);
    $event = Event::with('businesses')
        ->get();
    $test = $event->startdate;
    $test2 = $event->enddate;
    //something like if $today is not less that start date and not higher than end date, return that collection?
    dd($test);
    return view('events.showEvent', compact('event'));
}



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2sIEHFw
via IFTTT

Aucun commentaire:

Enregistrer un commentaire