Skip to content

Instantly share code, notes, and snippets.

@johnadan
Created June 6, 2023 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnadan/567a40f92dcf4fd26de4d0903dddce4f to your computer and use it in GitHub Desktop.
Save johnadan/567a40f92dcf4fd26de4d0903dddce4f to your computer and use it in GitHub Desktop.
List with query params in laravel api controller
<?php
public function index(Request $request)
{
UserLog::insertLog('Listed cities', URL::full());
$cities = AddressCity::query();
$provinceCode = $request->provinceCode;
if ($provinceCode) {
$cities = $cities->where('province_code', $provinceCode);
}
return response()->json([
'cities' => $cities->paginate(10)
]);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment