$validatedData = $request->validate([
'after' => 'nullable|date',
'before' => 'nullable|date',
+ 'order' => 'nullable|string',
+ 'with' => 'nullable|array',
+ 'with.*' => 'string',
]);
$events = Event::where('visible', '=', true);
if (isset($validatedData['before'])) {
$query->orWhere('end', '>', $validatedData['after']);
});
}
+ if (isset($validatedData['order'])) {
+ switch ($validatedData['order']) {
+ case 'recency':
+ $events->orderByRaw('start IS NOT NULL');
+ $events->orderByRaw('end IS NOT NULL');
+ $events->orderBy('end', 'DESC');
+ $events->orderBy('start', 'DESC');
+ $events->orderBy('name', 'ASC');
+ break;
+ }
+ }
+ if (isset($validatedData['with'])) {
+ if (in_array('description', $validatedData['with'])) {
+ $events->with('description');
+ }
+ }
return $events->get()->toJson();
}