isOperator() || Auth::user()->isAdmin(), 403); } public function rows(): array { $user = Auth::user(); return collect(NotificationPreference::CATEGORIES) ->mapWithKeys(fn (string $category) => [$category => NotificationPreference::rowFor($user, $category)]) ->all(); } public function toggle(string $category, string $field): void { abort_unless(in_array($category, NotificationPreference::CATEGORIES, true), 404); abort_unless(in_array($field, self::SCOPE_FIELDS, true), 404); $preference = NotificationPreference::query()->firstOrCreate( ['user_id' => Auth::id(), 'event_category' => $category], array_merge(['user_id' => Auth::id(), 'event_category' => $category], NotificationPreference::DEFAULTS[$category]) ); $preference->update([$field => ! $preference->$field]); } public function render() { return view('livewire.settings.notification-preferences', ['rows' => $this->rows()]); } }