public function getFestival($user = null, $city = null) { try { $response = []; $statusCode = 200; $festival = Festival::all(); if ($user != null) { $festival = Festival::where('user_id', $user)->get(); } elseif ($city != null) { $festival = Festival::where('city_id', $city)->get(); } elseif ($user != null && $city != null) { $festival = Festival::where('user_id', $user)->where('city_id', $city)->get(); } foreach ($festival as $f) { $response[] = ['id' => $f->id, 'name' => $f->name]; } } catch (Exception $e) { $statusCode = 404; } finally { return Response::json($response, $statusCode); } }