本文整理汇总了PHP中app\Event::whereBetween方法的典型用法代码示例。如果您正苦于以下问题:PHP Event::whereBetween方法的具体用法?PHP Event::whereBetween怎么用?PHP Event::whereBetween使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Event
的用法示例。
在下文中一共展示了Event::whereBetween方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index(Request $request)
{
$range = [];
// Add "From" date to query
$range[] = Carbon::parse($request->input('start'))->toDateTimeString();
// Add "To" date to query
$range[] = Carbon::parse($request->input('end'))->toDateTimeString();
return Event::whereBetween('start_time', $range)->where('hidden', false)->get();
}
示例2: getUpcomingEvents
/**
* Gets upcoming events for specified days. Defaults to 3 days
*
* @return array
*/
protected function getUpcomingEvents($days = 3)
{
$events = Event::whereBetween('start_time', [Carbon::now('America/Los_Angeles')->setTimezone('UTC'), Carbon::now('America/Los_Angeles')->addDays(2)->endOfDay()->setTimezone('UTC')])->get()->sortBy('start_time')->groupBy(function ($date) {
return Carbon::parse($date->start_time, 'UTC')->setTimezone('America/Los_Angeles')->format('l');
// grouping data by day
});
$result = [];
// Get events for the next 3 days (including nulls)
$date = Carbon::now('America/Los_Angeles');
for ($i = 0; $i < $days; $i++) {
$day = $date->format('l');
// Set day or null if not found
$result[$day] = isset($events[$day]) ? $events[$day] : null;
$date->addDay();
}
return $result;
}
示例3: show
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($slug)
{
// TODO Add a comments feed for each event.
$event = Event::findBySlug($slug);
// Check if exists
if (!$event) {
abort(404);
}
$event->load('creator', 'chair', 'registrations', 'guests');
// Look for events in the upcoming week
$range = [Carbon::now(), Carbon::now()->addDays(6)];
$upcoming_events = Event::whereBetween('start_time', $range)->get()->sortBy('start_time')->groupBy(function ($date) {
return Carbon::parse($date->start_time)->timezone('UTC')->setTimezone('America/Los_Angeles')->format('l');
// grouping data by day
});
return view('pages.event', compact('event', 'upcoming_events'));
}