*/ private const FIELDS = [ 'comment_on_presentation', 'form_reply', 'new_follower', 'news_announcements', 'weekly_product_updates', 'weekly_blog_digest', ]; public function authorize(): bool { return true; } /** * Accept "true"/"false"/"1"/"0"/1/0 strings from the frontend and coerce them to * real booleans before validation so the toggles actually persist. */ protected function prepareForValidation(): void { $normalized = []; foreach (self::FIELDS as $field) { if ($this->has($field)) { $normalized[$field] = filter_var($this->input($field), FILTER_VALIDATE_BOOL, FILTER_NULL_ON_FAILURE) ?? false; } } if ($normalized !== []) { $this->merge($normalized); } } /** * @return array */ public function rules(): array { return array_fill_keys(self::FIELDS, ['sometimes', 'boolean']); } /** * @return array */ public function messages(): array { return [ '*.boolean' => 'مقدار این تنظیم باید بله یا خیر باشد.', ]; } }