45 lines
1.6 KiB
PHP
45 lines
1.6 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace App\Http\Requests\Admin;
|
||
|
|
|
||
|
|
use App\Enums\EntityStatus;
|
||
|
|
use App\Enums\SourceLevel;
|
||
|
|
use Illuminate\Foundation\Http\FormRequest;
|
||
|
|
use Illuminate\Validation\Rule;
|
||
|
|
|
||
|
|
class ArticleRequest extends FormRequest
|
||
|
|
{
|
||
|
|
public function authorize(): bool
|
||
|
|
{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function rules(): array
|
||
|
|
{
|
||
|
|
$articleId = $this->route('article')?->id;
|
||
|
|
|
||
|
|
return [
|
||
|
|
'category_id' => ['nullable', 'integer', 'exists:categories,id'],
|
||
|
|
'source_id' => ['nullable', 'integer', 'exists:sources,id'],
|
||
|
|
'title' => ['required', 'string', 'max:200'],
|
||
|
|
'slug' => ['required', 'string', 'max:190', Rule::unique('articles', 'slug')->ignore($articleId)],
|
||
|
|
'excerpt' => ['required', 'string', 'max:320'],
|
||
|
|
'body' => ['required', 'string', 'min:100'],
|
||
|
|
'source_name' => ['nullable', 'string', 'max:160'],
|
||
|
|
'source_url' => ['nullable', 'url', 'max:2048'],
|
||
|
|
'source_level' => ['required', Rule::in(array_column(SourceLevel::cases(), 'value'))],
|
||
|
|
'last_verified_at' => ['nullable', 'date'],
|
||
|
|
'status' => ['required', Rule::in(array_column(EntityStatus::cases(), 'value'))],
|
||
|
|
'is_stale' => ['nullable', 'boolean'],
|
||
|
|
'stale_note' => ['nullable', 'string'],
|
||
|
|
'seo_title' => ['nullable', 'string', 'max:180'],
|
||
|
|
'seo_description' => ['nullable', 'string', 'max:320'],
|
||
|
|
'h1' => ['nullable', 'string', 'max:180'],
|
||
|
|
'canonical_url' => ['nullable', 'url', 'max:2048'],
|
||
|
|
'published_at' => ['nullable', 'date'],
|
||
|
|
];
|
||
|
|
}
|
||
|
|
}
|