48 lines
1.3 KiB
PHP
48 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Notifications;
|
|
|
|
use App\Models\Artwork;
|
|
use App\Models\User;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Notifications\Notification;
|
|
use Illuminate\Support\Str;
|
|
|
|
class ArtworkLikedNotification extends Notification
|
|
{
|
|
use Queueable;
|
|
|
|
public function __construct(
|
|
private readonly Artwork $artwork,
|
|
private readonly User $actor,
|
|
) {}
|
|
|
|
public function via(object $notifiable): array
|
|
{
|
|
return ['database'];
|
|
}
|
|
|
|
public function databaseType(object $notifiable): string
|
|
{
|
|
return 'artwork_liked';
|
|
}
|
|
|
|
public function toDatabase(object $notifiable): array
|
|
{
|
|
$label = $this->actor->name ?: $this->actor->username ?: 'Someone';
|
|
$slug = Str::slug((string) ($this->artwork->slug ?: $this->artwork->title)) ?: (string) $this->artwork->id;
|
|
|
|
return [
|
|
'type' => 'artwork_liked',
|
|
'artwork_id' => (int) $this->artwork->id,
|
|
'artwork_title' => $this->artwork->title,
|
|
'actor_id' => (int) $this->actor->id,
|
|
'actor_name' => $this->actor->name,
|
|
'actor_username' => $this->actor->username,
|
|
'message' => $label . ' liked your artwork',
|
|
'url' => route('art.show', ['id' => $this->artwork->id, 'slug' => $slug]),
|
|
];
|
|
}
|
|
} |