Getting records between two date in laravel eloquent

Share:
How to get records between two dates using Eloquent in Laravel5 ?
We can get records between two dates laravel5 with using Eloquent "whereBetween" method. Here sample function to get posts between two dates from database.

public function getPosts(){ 
 $fromDate = date('Y-m-d' . ' 00:00:00', time()); 
 $toDate = date('Y-m-d' . ' 22:00:40', time()); 
 $posts = POST:: where('user_id',$this->user_id) ->where('status',1)->whereBetween('posted_on',[$fromDate, $toDate])->get(); 
 return $posts; 


Top Laravel Interview questions and answers for Fresher and Experienced

No comments