File size: 838 Bytes
5f32fbd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php

declare(strict_types=1);

namespace App\Actions;

use App\Models\User;
use App\Notifications\LiveNotification;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Notification;

class Notify
{
    public static function to(
        User|int|string $userOrId,
        string $title,
        string $message,
        ?string $link = '#'
    ): void {
        $user = $userOrId instanceof User ? $userOrId : User::findOrFail($userOrId);

        $user->notify(new LiveNotification($message, $link, $title));
    }

    /**
     * @param  array<int, User>  $users
     */
    public static function toMany(
        array|Collection $users,
        string $title,
        string $message,
        ?string $link = '#'
    ): void {
        Notification::send($users, new LiveNotification($message, $link, $title));
    }
}