Files
sam-api/app/Http/Requests/Push/UpdateSettingsRequest.php

46 lines
1.3 KiB
PHP
Raw Permalink Normal View History

<?php
namespace App\Http\Requests\Push;
use App\Models\PushNotificationSetting;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class UpdateSettingsRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
return [
'settings' => ['required', 'array'],
'settings.*.notification_type' => [
'required',
'string',
Rule::in(PushNotificationSetting::getAllTypes()),
],
'settings.*.is_enabled' => ['required', 'boolean'],
'settings.*.sound' => [
'nullable',
'string',
Rule::in(PushNotificationSetting::getAllSounds()),
],
'settings.*.vibrate' => ['nullable', 'boolean'],
'settings.*.show_preview' => ['nullable', 'boolean'],
];
}
public function messages(): array
{
return [
'settings.required' => __('error.push.settings_required'),
'settings.*.notification_type.required' => __('error.push.type_required'),
'settings.*.notification_type.in' => __('error.push.type_invalid'),
'settings.*.is_enabled.required' => __('error.push.enabled_required'),
];
}
}