hasComposition()
* 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
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user