Skip to content

Instantly share code, notes, and snippets.

@BinaryKitten
Last active June 7, 2020 10:16
Show Gist options
  • Select an option

  • Save BinaryKitten/e36a88a22c5d32f482ab2f207579da63 to your computer and use it in GitHub Desktop.

Select an option

Save BinaryKitten/e36a88a22c5d32f482ab2f207579da63 to your computer and use it in GitHub Desktop.
$validWiths = [
'a' => 'a',
'b' => 'b',
'translated' => static function ($query) {
$query->withTrashed();
}
];
$with = $request->get('with');
$mealQuery = \App\Meal::query();
if ($with !== null) {
$withValue = array_filter(
array_map(
static function ($withValue) use ($validWiths) {
return $validWiths[$withValue] ?? null;
},
(array)$with
)
);
if (!empty($withValue)) {
$mealQuery = $mealQuery->with($withValue);
}
}
$meals = $mealQuery->withTrashed()
->where('created_at', '>', $timeTo)
->orWhere('updated_at', '>', $timeTo)
->orWhere('deleted_at', '>', $timeTo)
->get();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment