whisper-money/app/Http/Requests/UpdateSavingsGoalRequest.php

47 lines
1.1 KiB
PHP

<?php
namespace App\Http\Requests;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class UpdateSavingsGoalRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
/**
* @return array<string, ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'name' => [
'sometimes',
'required',
'string',
'max:255',
Rule::unique('labels', 'name')
->where('user_id', auth()->id())
->whereNull('deleted_at')
->ignore($this->route('savingsGoal')?->label_id),
],
'target_amount' => ['sometimes', 'required', 'integer', 'min:1'],
'target_date' => ['nullable', 'date'],
];
}
/**
* @return array<string, string>
*/
public function messages(): array
{
return [
'name.unique' => __('You already have a label or goal with this name.'),
];
}
}