php - use eloquent ORM to get data from database -
i have array of timestamps , want compare ones in table. code in controller :
public function create(){ $from = input::get('from'); //array of timestamps of current messages displayed $conv_id = input::get('conv_id'); //array of ids //get messages related array of ids $allmessages = messages::wherein('conv_id',$conv_id); //get messages in database have timestamps greater current ones displayed. $messages = $allmessages->where('created_at','>',$from); homecoming $messages->get()->reverse(); } this works a single timestamp passed. however, if an array of timestamps passed, laravel not able observe latest messages. have tried,
$messages = $allmessages->wherein('created_at','>',$from); but returns array string conversion error. suspect might using wrongly.
so i repeat, how messages in table have timestamps greater timestamps got input class?
i think can done using php's explode() want maintain codes 'laravel-ish' possible. if explode() unavoidable, please show me how utilize it. btw, bonus impression points improvement of code! give thanks you!
p.s. result of dd($from) :
array (size=2) 0 => string '2014-06-18 06:53:45' (length=19) 1 => string '2014-06-18 14:52:29' (length=19)
you need have, find latest date in array , utilize that.
this can done easily
$from = array('2014-06-18 09:10:32', '2014-06-17 10:52:25'); // input::get('from'); $conv_id = input::get('conv_id'); asort($from); // sort array of dates in order of earliest date first. $messages = messages::wherein('conv_id', $conv_id)->where('created_at', '>', end($from))->get(); this homecoming messages created_at timestamp greater latest date in $from array.
php arrays database laravel-4 eloquent
No comments:
Post a Comment