52 lines
1.8 KiB
PHP
52 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Admin;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class StoreDocumentRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return $this->user()->canManageDocuments();
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
$maxSizeKb = config('knowledgebase.upload.max_file_size', 20480);
|
|
|
|
return [
|
|
'category_id' => ['required', 'integer', 'exists:categories,id'],
|
|
'title' => ['required', 'string', 'max:255'],
|
|
'description' => ['nullable', 'string', 'max:1000'],
|
|
'file' => [
|
|
'required',
|
|
'file',
|
|
'mimes:pdf',
|
|
"max:{$maxSizeKb}",
|
|
],
|
|
'effective_date' => ['nullable', 'date'],
|
|
'expiry_date' => ['nullable', 'date', 'after_or_equal:effective_date'],
|
|
'tags' => ['nullable', 'array'],
|
|
'tags.*' => ['string', 'max:50'],
|
|
'language' => ['nullable', 'in:ms,en'],
|
|
'change_notes' => ['nullable', 'string', 'max:500'],
|
|
];
|
|
}
|
|
|
|
public function messages(): array
|
|
{
|
|
$maxMb = round(config('knowledgebase.upload.max_file_size', 20480) / 1024);
|
|
|
|
return [
|
|
'category_id.required' => 'Kategori wajib dipilih.',
|
|
'category_id.exists' => 'Kategori tidak wujud.',
|
|
'title.required' => 'Tajuk dokumen wajib diisi.',
|
|
'file.required' => 'Fail PDF wajib diupload.',
|
|
'file.mimes' => 'Hanya fail PDF yang dibenarkan.',
|
|
'file.max' => "Saiz fail tidak boleh melebihi {$maxMb}MB.",
|
|
'expiry_date.after_or_equal' => 'Tarikh luput mesti selepas atau sama dengan tarikh kuat kuasa.',
|
|
];
|
|
}
|
|
}
|