How to get records between two dates using Eloquent in Laravel 5

two dates Laravel 5 MAKE Create Custom helpers

How to get records between two dates using Eloquent in Laravel 5. This is Best solution for get record between two dates. We can get records between two dates laravel5 with using Eloquent “whereBetween” method. Here sample function to get posts between two dates from database.

Here is Code for get records between two dates using Eloquent in Laravel 5

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; 

Also Read : How to Create Custom Helper in laravel

Leave a Reply