feat: legal sections

This commit is contained in:
2026-05-24 13:20:04 +02:00
parent 3a74c2c34d
commit 8b162c8e4c
24 changed files with 1145 additions and 0 deletions
@@ -0,0 +1,34 @@
<?php
namespace App\Http\Controllers;
use App\Http\Resources\LegalDocumentResource;
use App\Models\LegalDocument;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
class LegalDocumentController extends Controller
{
public function index(Request $request): AnonymousResourceCollection
{
$query = LegalDocument::query()
->public()
->latest('published_at')
->latest('version');
if ($request->filled('type')) {
$query->where('type', $request->string('type')->toString());
}
return LegalDocumentResource::collection($query->get());
}
public function show(string $slug): LegalDocumentResource
{
$document = LegalDocument::publicForSlug($slug);
abort_if(! $document, 404, __('api.legal_documents.not_found'));
return new LegalDocumentResource($document);
}
}
@@ -0,0 +1,28 @@
<?php
namespace App\Http\Resources;
use App\Models\LegalDocument;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
/** @mixin LegalDocument */
class LegalDocumentResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'slug' => $this->slug,
'type' => $this->type?->value,
'typeLabel' => $this->type?->getLabel(),
'version' => $this->version,
'title' => $this->title,
'content' => $this->content,
'isActive' => $this->is_active,
'publishedAt' => $this->published_at,
'createdAt' => $this->created_at,
'updatedAt' => $this->updated_at,
];
}
}