First commit
This commit is contained in:
44
app/Http/Requests/Admin/StoreKnowledgeItemRequest.php
Normal file
44
app/Http/Requests/Admin/StoreKnowledgeItemRequest.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin;
|
||||
|
||||
use App\Models\KnowledgeItem;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreKnowledgeItemRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user()->canManageDocuments();
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'category_id' => ['required', 'integer', 'exists:categories,id'],
|
||||
'item_type' => ['required', 'in:' . implode(',', array_keys(KnowledgeItem::typeLabels()))],
|
||||
'title' => ['required', 'string', 'max:500'],
|
||||
'content' => ['required', 'string', 'max:10000'],
|
||||
'content_short' => ['nullable', 'string', 'max:500'],
|
||||
'tags' => ['nullable', 'array'],
|
||||
'tags.*' => ['string', 'max:50'],
|
||||
'language' => ['nullable', 'in:ms,en'],
|
||||
'effective_date' => ['nullable', 'date'],
|
||||
'expiry_date' => ['nullable', 'date'],
|
||||
'is_active' => ['boolean'],
|
||||
'is_public' => ['boolean'],
|
||||
];
|
||||
}
|
||||
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'category_id.required' => 'Kategori wajib dipilih.',
|
||||
'item_type.required' => 'Jenis item wajib dipilih.',
|
||||
'item_type.in' => 'Jenis item tidak sah.',
|
||||
'title.required' => 'Tajuk/soalan wajib diisi.',
|
||||
'content.required' => 'Kandungan/jawapan wajib diisi.',
|
||||
'content.max' => 'Kandungan terlalu panjang (had: 10,000 karakter).',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user