Skip to content

Commit 1e4ce67

Browse files
committed
Added welcome notification upon user creation
1 parent 5d92db2 commit 1e4ce67

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

app/Models/User.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
namespace App\Models;
44

55
use App\Models\Presenters\UserPresenter;
6+
use App\Notifications\GreetNotification;
67
use Illuminate\Database\Eloquent\Casts\Attribute;
78
use Illuminate\Database\Eloquent\Factories\HasFactory;
89
use Illuminate\Foundation\Auth\User as Authenticatable;
910
use Illuminate\Notifications\Notifiable;
11+
use Illuminate\Support\Facades\Notification;
1012
use Laravel\Sanctum\HasApiTokens;
1113
use NotificationChannels\WebPush\HasPushSubscriptions;
1214
use Orchid\Access\UserAccess;
@@ -87,6 +89,19 @@ class User extends Authenticatable
8789
'created_at',
8890
];
8991

92+
/**
93+
* Boot the model's events.
94+
*
95+
* @return void
96+
*/
97+
protected static function booted(): void
98+
{
99+
static::created(function (User $user) {
100+
Notification::send($user, new GreetNotification());
101+
});
102+
}
103+
104+
90105
/**
91106
* Throw an exception if email already exists, create admin user.
92107
*
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
namespace App\Notifications;
4+
5+
use App\Models\User;
6+
use App\Notifications\Channels\SiteChannel;
7+
use App\Notifications\Channels\SiteMessage;
8+
use Illuminate\Bus\Queueable;
9+
use Illuminate\Contracts\Queue\ShouldQueue;
10+
use Illuminate\Notifications\Messages\MailMessage;
11+
use Illuminate\Notifications\Notification;
12+
13+
class GreetNotification extends Notification
14+
{
15+
use Queueable;
16+
17+
/**
18+
* Create a new notification instance.
19+
*/
20+
public function __construct()
21+
{
22+
//
23+
}
24+
25+
/**
26+
* Get the notification's delivery channels.
27+
*
28+
* @return array<int, string>
29+
*/
30+
public function via(object $notifiable): array
31+
{
32+
return [
33+
SiteChannel::class,
34+
];
35+
}
36+
37+
/**
38+
* Get the app representation of the notification.
39+
*
40+
* @param mixed $user
41+
*
42+
* @return \Illuminate\Notifications\Messages\MailMessage
43+
*/
44+
public function toSite(User $user)
45+
{
46+
return (new SiteMessage())
47+
->title('Присоединяйтесь к нашему Telegram-каналу прямо сейчас для актуальных новостей и эксклюзивных анонсов.')
48+
->action(config('services.telegram.channel_url'), 'Подписаться');
49+
}
50+
51+
/**
52+
* Get the array representation of the notification.
53+
*
54+
* @return array<string, mixed>
55+
*/
56+
public function toArray(object $notifiable): array
57+
{
58+
return [
59+
//
60+
];
61+
}
62+
}

0 commit comments

Comments
 (0)