* renderRegion() * draft and published-state handling * document and placement scheduling * disabled-placement filtering * ordered region rendering * safe fallback when composition tables or document views are missing * compatibility with common alternative column names
38 lines
1.3 KiB
PHP
38 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Modules\Content\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
use Modules\Content\Models\ContentDocument;
|
|
|
|
final class SaveContentDocumentRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool { return true; }
|
|
|
|
public function rules(): array
|
|
{
|
|
$document = $this->route('document');
|
|
return [
|
|
'content_type_id' => ['required','integer','exists:content_types,id'],
|
|
'title' => ['required','string','max:255'],
|
|
'slug' => ['nullable','string','max:255', Rule::unique('content_documents','slug')->ignore($document instanceof ContentDocument ? $document->id : null)],
|
|
'status' => ['required', Rule::in(['draft','published','archived'])],
|
|
'data_json' => ['required','json'],
|
|
'published_at' => ['nullable','date'],
|
|
'expires_at' => ['nullable','date','after:published_at'],
|
|
];
|
|
}
|
|
|
|
public function payload(): array
|
|
{
|
|
$validated = $this->validated();
|
|
$validated['slug'] = filled($validated['slug'] ?? null) ? $validated['slug'] : str($validated['title'])->slug();
|
|
$validated['data'] = json_decode($validated['data_json'], true, flags: JSON_THROW_ON_ERROR);
|
|
unset($validated['data_json']);
|
|
return $validated;
|
|
}
|
|
}
|