php - Laravel - Compare Dates -
im using laravell framework. banner events, showing events exist after current date.
this current function on routes.php
route::get('/banner', function() { $date = time(); $events = event::where('date', '>', $date)->get(); return view::make('banner')->with('events', $events); });
in view, shows events, doesnt matter if before or after current date. , if change:
$events = event::where('date', '<', $date)->get();
this dont show anything.
the view working good, main problem here cant find how fix this.
you can this.
in event
model add following line.
protected $dates = ['date'];
by doing when event
saved date
saved carbon instance.
then when query this.
$events = event::where('date', '>', carbon::now())->get();
make sure import carbon
this.
use carbon\carbon;
refer fun dates laracasts more details.
Comments
Post a Comment