Filter a Laravel collection by date -
in code given below $allzip["assigned_date"] has value 2016-07-27 18:12:26. when try compare created_at field timestamp field well, result empty collection.
$filtered_datas = $datas->filter(function ($data) use($allzip) { return $data->zip == $allzip["zip"] && $data->created_at < $allzip["assigned_date"]; }); there data in database zip field matching value $allzip["zip"] , created_at field value 2016-07-19 18:12:26. should return 1 item in collection returns empty collection instead. why?
make sure dates datetime or carbon instances, not strings. otherwise, comparison operator shouldn't working expected.
Comments
Post a Comment