Advertisement
rodro1

time date query scope laravel carbon

Sep 19th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.04 KB | None | 0 0
  1. public function scopeJoinedToday($query)
  2.     {
  3.        
  4.         return $query->where('role', 3)->whereBetween('created_at', [Carbon::now()->format('Y-m-d').' 00:00:00' , Carbon::now()->format('Y-m-d').' 23:59:59'] );
  5.        
  6.     }
  7.    
  8.    
  9.     public function scopeJoinedThisWeek($query)
  10.     {
  11.        
  12.         return $query->where('role', 3)->whereBetween('created_at', [ Carbon::now()->addDays(-7)->format('Y-m-d').' 00:00:00' , Carbon::now()->format('Y-m-d').' 23:59:59'] );
  13.        
  14.     }
  15.    
  16.    
  17.     public function scopeJoinedLastMonth($query)
  18.     {
  19.        
  20.         return $query->where('role', 3)->whereBetween('created_at', [ Carbon::now()->addMonths(-1)->format('Y-m-d').' 00:00:00' , Carbon::now()->format('Y-m-d').' 23:59:59'] );
  21.        
  22.     }
  23.  
  24.     public function scopeJoinedThreeMonthsAgo($query)
  25.     {
  26.        
  27.         return $query->where('role', 3)->whereBetween('created_at', [ Carbon::now()->addMonths(-6)->format('Y-m-d').' 00:00:00' , Carbon::now()->addMonths(-3)->format('Y-m-d').' 23:59:59'] );
  28.        
  29.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement