36 lines
938 B
PHP
36 lines
938 B
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Api;
|
|
|
|
use App\Support\Settings;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Validator;
|
|
|
|
class StoreTicketMessageRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'body' => ['required', 'string'],
|
|
'internal' => ['sometimes', 'boolean'],
|
|
'author_name' => ['sometimes', 'nullable', 'string', 'max:255'],
|
|
'attachments' => ['sometimes', 'array'],
|
|
'attachments.*' => ['file'],
|
|
];
|
|
}
|
|
|
|
public function withValidator(Validator $validator): void
|
|
{
|
|
$validator->after(function (Validator $validator) {
|
|
if ($error = Settings::validateAttachments($this->file('attachments', []))) {
|
|
$validator->errors()->add('attachments', $error);
|
|
}
|
|
});
|
|
}
|
|
}
|