send($user, 'level_up', [ 'character_name' => $character->name, 'level' => $newLevel, ]); } /** * Send a money earned notification */ public function sendMoneyEarned(User $user, int $amount, string $reason): Notification { return $this->send($user, 'money_earned', [ 'amount' => $amount, 'reason' => $reason, ]); } /** * Send a money spent notification */ public function sendMoneySpent(User $user, int $amount, string $reason): Notification { return $this->send($user, 'money_spent', [ 'amount' => $amount, 'reason' => $reason, ]); } /** * Send an energy low notification */ public function sendEnergyLow(User $user, Character $character): Notification { return $this->send($user, 'energy_low', [ 'character_name' => $character->name, 'energy' => $character->energy, 'max_energy' => $character->max_energy, ]); } /** * Send a health low notification */ public function sendHealthLow(User $user, Character $character): Notification { return $this->send($user, 'health_low', [ 'character_name' => $character->name, 'health' => $character->health, 'max_health' => $character->max_health, ]); } /** * Send a character dead notification */ public function sendCharacterDead(User $user, Character $character): Notification { return $this->send($user, 'character_dead', [ 'character_name' => $character->name, 'revive_cost' => config('game.health.hospital_cost', 1000), ]); } /** * Send a character revived notification */ public function sendCharacterRevived(User $user, Character $character): Notification { return $this->send($user, 'character_revived', [ 'character_name' => $character->name, ]); } /** * Get unread notifications for a user */ public function getUnread(User $user): \Illuminate\Database\Eloquent\Collection { return $user->notifications() ->whereNull('read_at') ->orderBy('created_at', 'desc') ->get(); } /** * Get all notifications for a user */ public function getAll(User $user, int $limit = 20): \Illuminate\Database\Eloquent\Collection { return $user->notifications() ->orderBy('created_at', 'desc') ->take($limit) ->get(); } /** * Mark a notification as read */ public function markAsRead(Notification $notification): void { $notification->markAsRead(); } /** * Mark all notifications as read for a user */ public function markAllAsRead(User $user): int { return $user->notifications() ->whereNull('read_at') ->update(['read_at' => now()]); } /** * Delete a notification */ public function delete(Notification $notification): bool { return $notification->delete(); } /** * Delete all read notifications for a user */ public function deleteAllRead(User $user): int { return $user->notifications() ->whereNotNull('read_at') ->delete(); } /** * Get the count of unread notifications for a user */ public function getUnreadCount(User $user): int { return $user->notifications() ->whereNull('read_at') ->count(); } }