38 lines
1.1 KiB
PHP
38 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use App\Enums\PostStatus;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
use Illuminate\Validation\Rules\Enum;
|
|
|
|
class StorePostRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'category_id' => ['nullable', 'exists:categories,id'],
|
|
'title' => ['required', 'string', 'max:255'],
|
|
'slug' => ['nullable', 'string', 'max:255', Rule::unique('posts', 'slug')],
|
|
'excerpt' => ['nullable', 'string', 'max:255'],
|
|
'body' => ['required', 'string'],
|
|
'featured_image' => ['nullable', 'string'],
|
|
'status' => ['required', new Enum(PostStatus::class)],
|
|
'published_at' => ['nullable', 'date'],
|
|
'meta_title' => ['nullable', 'string', 'max:60'],
|
|
'meta_description' => ['nullable', 'string', 'max:160'],
|
|
'tags' => ['sometimes', 'array'],
|
|
'tags.*' => ['integer', 'exists:tags,id'],
|
|
];
|
|
}
|
|
}
|