80 lines
2.1 KiB
PHP
80 lines
2.1 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Controllers\Bo;
|
||
|
|
|
||
|
|
use App\Http\Controllers\Controller;
|
||
|
|
use App\Http\Requests\Bo\SectionPages\UpdateSectionPageRequest;
|
||
|
|
use App\Models\SectionPage;
|
||
|
|
use App\Models\StaticPage;
|
||
|
|
use App\Services\StaticPage\SectionPageService;
|
||
|
|
use Illuminate\Http\JsonResponse;
|
||
|
|
|
||
|
|
class SectionPageController extends Controller
|
||
|
|
{
|
||
|
|
public function __construct(
|
||
|
|
private readonly SectionPageService $service
|
||
|
|
) {}
|
||
|
|
|
||
|
|
public function index(StaticPage $page): JsonResponse
|
||
|
|
{
|
||
|
|
return response()->json([
|
||
|
|
'data' => $this->service->getByPage($page),
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function store(UpdateSectionPageRequest $request, StaticPage $page): JsonResponse
|
||
|
|
{
|
||
|
|
$section = $this->service->create($page, $request->validated());
|
||
|
|
|
||
|
|
return response()->json($section);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function show(SectionPage $section): JsonResponse
|
||
|
|
{
|
||
|
|
return response()->json([
|
||
|
|
'data' => $section,
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
|
||
|
|
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,
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function destroy(SectionPage $section): JsonResponse
|
||
|
|
{
|
||
|
|
$this->service->delete($section);
|
||
|
|
|
||
|
|
return response()->json([
|
||
|
|
'message' => 'Section supprimée',
|
||
|
|
'data' => $section,
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function toggleVisibility(SectionPage $section): JsonResponse
|
||
|
|
{
|
||
|
|
$section = $this->service->toggleVisibility($section);
|
||
|
|
|
||
|
|
return response()->json([
|
||
|
|
'data' => $section,
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
}
|