2026-06-23 10:10:28 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Modules\History\Requests;
|
|
|
|
|
|
2026-07-18 09:34:18 +00:00
|
|
|
use App\Modules\History\Models\HistoryType;
|
|
|
|
|
use Illuminate\Contracts\Validation\Validator;
|
2026-06-23 10:10:28 +00:00
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
|
|
|
|
|
|
class CreateHistoryEntryRequest extends FormRequest
|
|
|
|
|
{
|
|
|
|
|
public function authorize(): bool { return true; }
|
|
|
|
|
|
|
|
|
|
public function rules(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
2026-07-18 09:34:18 +00:00
|
|
|
'history_entry_type_id' => ['required', 'integer', 'exists:history_types,id'],
|
2026-06-23 10:10:28 +00:00
|
|
|
'body' => ['required', 'string', 'max:65535'],
|
2026-07-18 09:34:18 +00:00
|
|
|
// The picker emits a naive local datetime; presence is enforced
|
|
|
|
|
// conditionally below based on the chosen type.
|
|
|
|
|
'occurred_at' => ['nullable', 'date_format:Y-m-d\TH:i:s'],
|
2026-06-23 10:10:28 +00:00
|
|
|
];
|
|
|
|
|
}
|
2026-07-18 09:34:18 +00:00
|
|
|
|
|
|
|
|
public function withValidator(Validator $validator): void
|
|
|
|
|
{
|
|
|
|
|
$validator->after(function (Validator $validator) {
|
|
|
|
|
$typeId = $this->input('history_entry_type_id');
|
|
|
|
|
if (! $typeId) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$type = HistoryType::find($typeId);
|
|
|
|
|
if ($type && $type->requires_datetime && ! $this->filled('occurred_at')) {
|
|
|
|
|
$validator->errors()->add(
|
|
|
|
|
'occurred_at',
|
|
|
|
|
'Für diesen Verlaufstyp sind Datum und Uhrzeit erforderlich.'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2026-06-23 10:10:28 +00:00
|
|
|
}
|