php - Eloquent select from database, get results newer than a given unix timestamp -


i select rows database newer specified unix timestamp specified in parameters.

the column created_at datetime in table tracks. parameter $timestamp unix timestamp (an integer).

so trying tracks::where('created_at','>=',$timestamp)->get(); returns tracks, no matter $timestamp specify.

however can see type problem, , have tried different things writing 'unix_timestamp(created_at)' instead of created_at, no luck.

so assume there elegant , simple way of doing this. can me?

there 2 ways solve this.

  1. use tracks::where(db::raw('unix_timestamp(created_at)'),'>=',$timestamp)
  2. use datetime or carbon object.

like this:

$timestamp = carbon\carbon::createfromtimestamp($timestamp); tracks::where('created_at','>=',$timestamp)->get(); 

Comments

Popular posts from this blog

javascript - How to name a jQuery function to make a browser's back button work? -

python - Django-easy-pdf: xhtml2pdf reporting reportlab 2.2+ is required, but 3.0 installed -

collision detection - C++ library for mesh to mesh intersection: what is available? -