2023-01-13 14:12:49 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Notifications\User;
|
|
|
|
|
|
|
|
use App\Notifications\Channels\WebChannel;
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
|
|
use Illuminate\Notifications\Notification;
|
|
|
|
|
|
|
|
class UserNotification extends Notification implements ShouldQueue
|
|
|
|
{
|
|
|
|
use Queueable;
|
|
|
|
|
|
|
|
public string $title;
|
2023-01-30 16:14:07 +00:00
|
|
|
|
2023-01-13 14:12:49 +00:00
|
|
|
public string $content;
|
2023-01-30 16:14:07 +00:00
|
|
|
|
2023-01-13 14:12:49 +00:00
|
|
|
public bool $send_mail;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new notification instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2023-01-17 17:29:13 +00:00
|
|
|
public function __construct(string $title, string $content, bool $send_mail = false)
|
2023-01-13 14:12:49 +00:00
|
|
|
{
|
|
|
|
$this->title = $title;
|
|
|
|
$this->content = $content;
|
|
|
|
$this->send_mail = $send_mail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the notification's delivery channels.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function via(): array
|
|
|
|
{
|
|
|
|
$channels = [WebChannel::class];
|
|
|
|
|
|
|
|
if ($this->send_mail) {
|
|
|
|
$channels[] = 'mail';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $channels;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the mail representation of the notification.
|
|
|
|
*
|
|
|
|
* @return MailMessage
|
|
|
|
*/
|
|
|
|
public function toMail(): MailMessage
|
|
|
|
{
|
|
|
|
return (new MailMessage)->subject($this->title)->markdown('mail.common', [
|
|
|
|
'title' => $this->title,
|
|
|
|
'content' => $this->content,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the array representation of the notification.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function toArray(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'title' => $this->title,
|
|
|
|
'content' => $this->content,
|
2023-01-13 14:41:28 +00:00
|
|
|
'event' => 'notifications',
|
2023-01-13 14:12:49 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|