feat: Add legal pages API and seeding

This commit is contained in:
2025-09-09 21:22:58 +02:00
parent 81958899a6
commit 57949c8b5f
3 changed files with 433 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
<?php
namespace App\Http\Controllers\Api;
use App\Models\LegalPage;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller as BaseController;
class LegalController extends BaseController
{
public function show(Request $request, string $slug)
{
$locale = $request->query('lang', 'de');
// Support common English aliases as fallbacks
$s = strtolower($slug);
$aliasMap = [
'imprint' => 'impressum',
'privacy' => 'datenschutz',
'terms' => 'agb',
];
$resolved = $aliasMap[$s] ?? $s;
$page = LegalPage::query()
->where('slug', $resolved)
->where('is_published', true)
->orderByDesc('version')
->first();
if (! $page) {
return response()->json(['error' => ['code' => 'not_found', 'message' => 'Legal page not found']], 404);
}
$title = $page->title[$locale] ?? $page->title[$page->locale_fallback] ?? $page->title['de'] ?? $page->title['en'] ?? $page->slug;
$body = $page->body_markdown[$locale] ?? $page->body_markdown[$page->locale_fallback] ?? reset($page->body_markdown);
return response()->json([
'slug' => $page->slug,
'version' => (int) $page->version,
'effective_from' => optional($page->effective_from)->toIso8601String(),
'locale' => $locale,
'title' => $title,
'body_markdown' => (string) $body,
])->header('Cache-Control', 'no-store');
}
}