Skip to content

Instantly share code, notes, and snippets.

@mdunbavan
Last active August 29, 2015 14:27
Show Gist options
  • Select an option

  • Save mdunbavan/b80462e385890b87a1fb to your computer and use it in GitHub Desktop.

Select an option

Save mdunbavan/b80462e385890b87a1fb to your computer and use it in GitHub Desktop.
Query chains
NOW
Example: "Burger and fries for £10 - every Wednesday from 12:00 til 15:00"
--
Offer day matches the current day
AND
Current time is later than the offer start time
--
LATER
Example: "2 for 1 cocktails - Tuesday & Wednesday from 17:00 til 20:00"
--
Offer day matches the current day
AND
Offer start time is later than the current time
--
TOMORROW
Example: "Any cocktail for £5 - every Thursday from 17:00 til 20:00"
--
Offer day matches the day after the current day
--
FEATURED
Example: "Paddle Round the Pier - Wednesday 12th August 2015 from 12:00 til 20:00"
--
Featured date matches the current date
AND
Current time is later than the offer start time
<?php
/**
* Show all offers queries by current date
*
* Get a JSON representation of all the offers.
* @Get("/")
* @Versions({"v1"})
*/
public function getOffers(Offer $offer)
{
$mytime = Carbon::now('Europe/London');
$currentTime = $mytime->format('H:i');
$today = $mytime->format('m/d/Y');
$day = $mytime->format('l');
$tomorrow = Carbon::now()->addDay(1)->format('l');
$thisDay = strtolower($day);
$offerWhen = $offer['offer_when'];
foreach(Offer::all() as $offerObject){
$the_days = $offerObject['days'];
$featured = $offerObject['featured_date'];
$start_time = $offerObject['offer_start_time'];
$end_time = $offerObject['offer_end_time'];
$ft = $offerObject::where('featured_date', '=', $featured)->get();
$offerObject::where('days', 'LIKE', '%' . strtolower($tomorrow) . '%')
->update(['offer_when' => 'tomorrow']);
$offerObject::where('days', 'LIKE', '%' . $thisDay . '%')
->where('offer_start_time', '>', 'current_time')
->update(['offer_when' => 'later']);
$offerObject::where('days', 'LIKE', '%' . $thisDay . '%')
->whereBetween('current_time', array($start_time,$end_time))
->update(['offer_when' => 'now']);
$offersAll = $offerObject::where('days', 'LIKE', '%' . $thisDay . '%')
->orWhere('days', 'LIKE', '%' . strtolower($tomorrow) . '%')
->get();
return $offersAll;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment