daily pastebin goal
14%
SHARE
TWEET

Untitled

a guest Jun 21st, 2018 46 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * @return IlluminateDatabaseEloquentRelationsHasMany
  3.  */
  4. public function pubSchedules()
  5. {
  6.     return $this->hasMany( Schedule::class );
  7. }
  8.    
  9. /**
  10.  * @return IlluminateDatabaseEloquentRelationsBelongsTo
  11.  */
  12. public function pub()
  13. {
  14.     return $this->belongsTo(Pub::class);
  15. }
  16.    
  17. public static function isPubCurrentlyOpen($pubs)
  18. {
  19.  
  20.     $pubs->whereHas('pubSchedules', function ($pubs) {
  21.         $pubs->where('week_day', Carbon::now()->dayOfWeek)
  22.             ->whereRaw(
  23.                 "'" . Carbon::now('Europe/Madrid')->format("H:i:s") .
  24.                     "' BETWEEN opening_time AND closing_time
  25.  
  26.                     "
  27.             );
  28.     } );
  29.  }
  30.    
  31. SELECT *,
  32.  CONCAT(YEAR(NOW()), '-', MONTH(NOW()), '-', `week_day`, ' ',
  33.   `opening_time`) AS `opening_datetime`,
  34.    IF(`closing_time` < `opening_time`,
  35.    CONCAT(YEAR(NOW()), '-', MONTH(NOW()), '-', `week_day` + 1, ' ',
  36.    `closing_time`),
  37.    CONCAT(YEAR(NOW()), '-', MONTH(NOW()), '-', `week_day`, ' ',
  38.    `closing_time`)
  39. ) AS `closing_datetime`
  40. FROM tappear_borrador.schedules
  41. ;
  42.    
  43. $pubs->whereHas('pubSchedules', function ($pubs) {
  44.         $pubs->where('week_day', Carbon::now()->dayOfWeek)
  45.             ->whereRaw(
  46.                 "'" . Carbon::now('Europe/Madrid')->format('Y-m-d H:i:s') .
  47.                 "' BETWEEN CONCAT(YEAR(NOW()), '-', MONTH(NOW()), '-', ".Carbon::now()->dayOfWeek.", ' ', opening_time)
  48.                     AND IF(closing_time < opening_time,
  49.                             CONCAT(YEAR(NOW()), '-', MONTH(NOW()), '-', ".Carbon::now()->dayOfWeek." + 1, ' ', closing_time),
  50.                             CONCAT(YEAR(NOW()), '-', MONTH(NOW()), '-', ".Carbon::now()->dayOfWeek.", ' ', closing_time)
  51.                     )
  52.  
  53.                     "
  54.             );
  55.     } );
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top