2018-01-27 10:35:56 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Notifications;
|
|
|
|
|
|
|
|
use App\Models\Reply;
|
|
|
|
use Illuminate\Bus\Queueable;
|
2018-01-29 17:17:57 +00:00
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
2018-01-27 10:35:56 +00:00
|
|
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
|
|
use Illuminate\Notifications\Notification;
|
|
|
|
|
2018-01-29 17:17:57 +00:00
|
|
|
class TopicReplied extends Notification implements ShouldQueue
|
2018-01-27 10:35:56 +00:00
|
|
|
{
|
|
|
|
use Queueable;
|
|
|
|
|
|
|
|
public $replay;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new notification instance.
|
|
|
|
* @param Reply $reply
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct(Reply $reply)
|
|
|
|
{
|
|
|
|
$this->replay = $reply;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the notification's delivery channels.
|
|
|
|
*
|
|
|
|
* @param mixed $notifiable
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function via($notifiable)
|
|
|
|
{
|
2018-01-29 17:17:57 +00:00
|
|
|
return ['database', 'mail'];
|
2018-01-27 10:35:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the mail representation of the notification.
|
|
|
|
*
|
|
|
|
* @param mixed $notifiable
|
|
|
|
* @return \Illuminate\Notifications\Messages\MailMessage
|
|
|
|
*/
|
|
|
|
public function toMail($notifiable)
|
|
|
|
{
|
2018-01-29 17:17:57 +00:00
|
|
|
$url = $this->replay->topic->link(['#reply' . $this->replay->id]);
|
2018-01-27 10:35:56 +00:00
|
|
|
return (new MailMessage)
|
2018-01-29 17:17:57 +00:00
|
|
|
->line('你的话题有新回复.')
|
|
|
|
->action('N查看回复', $url)
|
2018-01-27 10:35:56 +00:00
|
|
|
->line('Thank you for using our application!');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function toDataBase($notifiable)
|
|
|
|
{
|
|
|
|
$topic = $this->replay->topic;
|
|
|
|
|
2018-01-29 17:17:57 +00:00
|
|
|
$link = $topic->link(['#reply' . $this->replay->id]);
|
2018-01-27 10:35:56 +00:00
|
|
|
|
|
|
|
return [
|
|
|
|
'reply_id' => $this->replay->id,
|
|
|
|
'reply_content' => $this->replay->content,
|
|
|
|
'user_id' => $this->replay->user->id,
|
|
|
|
'user_name' => $this->replay->user->name,
|
|
|
|
'user_avatar' => $this->replay->user->avatar,
|
|
|
|
'topic_link' => $link,
|
|
|
|
'topic_id' => $topic->id,
|
|
|
|
'topic_title' => $topic->title
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the array representation of the notification.
|
|
|
|
*
|
|
|
|
* @param mixed $notifiable
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function toArray($notifiable)
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
//
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|