Skip to content

Commit e5b1b50

Browse files
authored
Merge pull request #2610 from codeeu/fix-search
Fix SearchController response structure for Vue compatibility
2 parents 1d1272d + d828260 commit e5b1b50

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

app/Http/Controllers/SearchController.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @Author: Bernard Hanna
55
* @Date: 2025-02-13 15:56:27
66
* @Last Modified by: Bernard Hanna
7-
* @Last Modified time: 2025-03-21 17:31:05
7+
* @Last Modified time: 2025-03-21 17:39:36
88
*/
99

1010

@@ -52,10 +52,9 @@ public function search(Request $request): View
5252
if (! is_null($country_iso)) {
5353
$country = Country::where('iso', $country_iso)->first();
5454
if ($country) {
55-
$country->translation = __('countries.'.$country->name);
55+
$country->translation = __('countries.' . $country->name);
5656
$selected_country[] = $country;
5757
}
58-
5958
}
6059

6160
$current_year = Carbon::now()->year;
@@ -71,13 +70,12 @@ public function searchPOST(EventFilters $filters, Request $request)
7170
{
7271
$events = $this->getEvents($filters);
7372

74-
//Log::info($request->input('page'));
75-
if ($request->input('page')) {
76-
$result = [$events];
77-
} else {
73+
$eventsMap = null;
74+
75+
// Only fetch map data if not paginating
76+
if (! $request->input('page')) {
7877
Log::info('no page');
7978
$eventsMap = $this->getAllEventsToMap($filters);
80-
$result = [$events, $eventsMap];
8179
}
8280

8381
return response()->json([
@@ -94,7 +92,7 @@ public function searchPOST(EventFilters $filters, Request $request)
9492
'to' => $events->lastItem(),
9593
'total' => $events->total(),
9694
],
97-
'map' => isset($eventsMap) ? $eventsMap->toArray() : null
95+
'map' => $eventsMap ? $eventsMap->toArray() : null
9896
]);
9997
}
10098

@@ -118,7 +116,6 @@ protected function getEvents(EventFilters $filters)
118116
}
119117

120118
return $events->get('future')->merge($events->get('past'))->paginate(12);
121-
122119
}
123120

124121
protected function getAllEventsToMap(EventFilters $filters)
@@ -129,7 +126,7 @@ protected function getAllEventsToMap(EventFilters $filters)
129126
$composed_key = '';
130127

131128
foreach ($flattened as $value) {
132-
$composed_key .= $value.',';
129+
$composed_key .= $value . ',';
133130
}
134131

135132
$value = Cache::get($composed_key, function () use ($composed_key, $filters) {
@@ -150,6 +147,5 @@ protected function getAllEventsToMap(EventFilters $filters)
150147
Log::info("Serving from cache [{$composed_key}]");
151148

152149
return $value;
153-
154150
}
155151
}

0 commit comments

Comments
 (0)