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

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

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