File tree Expand file tree Collapse file tree 2 files changed +77
-0
lines changed Expand file tree Collapse file tree 2 files changed +77
-0
lines changed Original file line number Diff line number Diff line change 3
3
namespace App \Models ;
4
4
5
5
use App \Models \Presenters \UserPresenter ;
6
+ use App \Notifications \GreetNotification ;
6
7
use Illuminate \Database \Eloquent \Casts \Attribute ;
7
8
use Illuminate \Database \Eloquent \Factories \HasFactory ;
8
9
use Illuminate \Foundation \Auth \User as Authenticatable ;
9
10
use Illuminate \Notifications \Notifiable ;
11
+ use Illuminate \Support \Facades \Notification ;
10
12
use Laravel \Sanctum \HasApiTokens ;
11
13
use NotificationChannels \WebPush \HasPushSubscriptions ;
12
14
use Orchid \Access \UserAccess ;
@@ -87,6 +89,19 @@ class User extends Authenticatable
87
89
'created_at ' ,
88
90
];
89
91
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
+
90
105
/**
91
106
* Throw an exception if email already exists, create admin user.
92
107
*
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments