Files
SkinbaseNova/app/Notifications/WorldRewardGrantedNotification.php

47 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Notifications;
use App\Models\WorldRewardGrant;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
class WorldRewardGrantedNotification extends Notification
{
use Queueable;
public function __construct(private readonly WorldRewardGrant $grant)
{
}
public function via(object $notifiable): array
{
return ['database'];
}
public function databaseType(object $notifiable): string
{
return 'world_reward_granted';
}
public function toDatabase(object $notifiable): array
{
$world = $this->grant->world;
$rewardType = $this->grant->reward_type;
$title = trim(($world?->title ?? 'World') . ' ' . $rewardType->label());
return [
'type' => 'world_reward_granted',
'world_reward_grant_id' => (int) $this->grant->id,
'world_id' => (int) ($world?->id ?? 0),
'world_slug' => (string) ($world?->slug ?? ''),
'reward_type' => $rewardType->value,
'title' => $title,
'message' => 'You earned the ' . $title . ' reward.',
'xp_reward' => $rewardType->xpReward(),
'url' => route('dashboard.notifications'),
];
}
}