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

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -