46 lines
1.4 KiB
PHP
46 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\StoicFaq;
|
|
use App\Models\StoicFaqSection;
|
|
use App\Models\StoicPage;
|
|
use App\Services\Stoic;
|
|
use App\Support\StorePlaceholders;
|
|
use Illuminate\Support\Str;
|
|
use Illuminate\View\View;
|
|
|
|
/**
|
|
* FAQ page: pages/faq.md lists the sections, each section lists its FAQs
|
|
* (both Stoic relations, so the order is the editor's). Answers are markdown
|
|
* and can use the same store placeholders as the legal pages.
|
|
*/
|
|
class FaqController extends Controller
|
|
{
|
|
public function index(string $locale, StorePlaceholders $placeholders): View
|
|
{
|
|
$page = StoicPage::localized('faq');
|
|
|
|
if (! $page) {
|
|
abort(404);
|
|
}
|
|
|
|
$sections = Stoic::localizedRelation(StoicFaqSection::class, $page->sections, 'faq-sections')
|
|
->map(function (StoicFaqSection $section) use ($placeholders) {
|
|
$section->items = Stoic::localizedRelation(StoicFaq::class, $section->faqs, 'faqs')
|
|
->map(fn (StoicFaq $faq) => $faq->forceFill([
|
|
'answer' => Str::markdown($placeholders->fill($faq->content ?? '')),
|
|
]));
|
|
|
|
return $section;
|
|
})
|
|
->filter(fn (StoicFaqSection $section) => $section->items->isNotEmpty())
|
|
->values();
|
|
|
|
return view('faq', [
|
|
'page' => $page,
|
|
'sections' => $sections,
|
|
]);
|
|
}
|
|
}
|