json([ 'data' => $this->service->getByPage($page), ]); } /** * Return a single section. * * @param SectionPage $section * @return JsonResponse */ public function show(SectionPage $section): JsonResponse { return response()->json([ 'data' => $section, ]); } /** * Update an existing section. * Merges uploaded files into the validated data before updating. * * @param UpdateSectionPageRequest $request * @param SectionPage $sectionPage * @return JsonResponse */ public function update(UpdateSectionPageRequest $request, SectionPage $sectionPage): JsonResponse { $validated = $request->validated(); // Merge files in data if ($request->hasFile('data')) { $validated['data'] = array_replace_recursive( $validated['data'] ?? [], $request->file('data') ); } $this->service->update($sectionPage, $validated); session()->flash('success', 'Section mise à jour avec succès.'); return response()->json([ 'message' => 'Section mise à jour', 'data' => $sectionPage, ]); } /** * Toggle the visibility of a section. * * @param SectionPage $section * @return JsonResponse */ public function toggleVisibility(SectionPage $section): JsonResponse { $section = $this->service->toggleVisibility($section); return response()->json([ 'data' => $section, ]); } }