Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @return IlluminateDatabaseEloquentRelationsHasMany
- */
- public function pubSchedules()
- {
- return $this->hasMany( Schedule::class );
- }
- /**
- * @return IlluminateDatabaseEloquentRelationsBelongsTo
- */
- public function pub()
- {
- return $this->belongsTo(Pub::class);
- }
- public static function isPubCurrentlyOpen($pubs)
- {
- $pubs->whereHas('pubSchedules', function ($pubs) {
- $pubs->where('week_day', Carbon::now()->dayOfWeek)
- ->whereRaw(
- "'" . Carbon::now('Europe/Madrid')->format("H:i:s") .
- "' BETWEEN opening_time AND closing_time
- "
- );
- } );
- }
- SELECT *,
- CONCAT(YEAR(NOW()), '-', MONTH(NOW()), '-', `week_day`, ' ',
- `opening_time`) AS `opening_datetime`,
- IF(`closing_time` < `opening_time`,
- CONCAT(YEAR(NOW()), '-', MONTH(NOW()), '-', `week_day` + 1, ' ',
- `closing_time`),
- CONCAT(YEAR(NOW()), '-', MONTH(NOW()), '-', `week_day`, ' ',
- `closing_time`)
- ) AS `closing_datetime`
- FROM tappear_borrador.schedules
- ;
- $pubs->whereHas('pubSchedules', function ($pubs) {
- $pubs->where('week_day', Carbon::now()->dayOfWeek)
- ->whereRaw(
- "'" . Carbon::now('Europe/Madrid')->format('Y-m-d H:i:s') .
- "' BETWEEN CONCAT(YEAR(NOW()), '-', MONTH(NOW()), '-', ".Carbon::now()->dayOfWeek.", ' ', opening_time)
- AND IF(closing_time < opening_time,
- CONCAT(YEAR(NOW()), '-', MONTH(NOW()), '-', ".Carbon::now()->dayOfWeek." + 1, ' ', closing_time),
- CONCAT(YEAR(NOW()), '-', MONTH(NOW()), '-', ".Carbon::now()->dayOfWeek.", ' ', closing_time)
- )
- "
- );
- } );
Add Comment
Please, Sign In to add comment