最近发表的评论
  • 为什么发了两次邮件? at 9个月前

    我这边的代码试过正常收到一封邮件。

    ReplyObserver.php

    <?php
    
    namespace App\Observers;
    
    use App\Models\Reply;
    
    // creating, created, updating, updated, saving,
    // saved,  deleting, deleted, restoring, restored
    
    use App\Notifications\TopicReplied;
    
    class ReplyObserver
    {
        public function creating(Reply $reply)
        {
            $reply->content = clean($reply->content, 'user_topic_body');
        }
    
        public function updating(Reply $reply)
        {
            //
        }
    
        public function created(Reply $reply)
        {
            $topic = $reply->topic;
            $topic->increment('reply_count', 1);
    
            // 通知作者话题被回复了
            $topic->user->notify(new TopicReplied($reply));
        }
    
        public function deleted(Reply $reply)
        {
            $reply->topic->decrement('reply_count', 1);
        }
    }

    TopicReplied.php

    <?php
    
    namespace App\Notifications;
    
    use Illuminate\Bus\Queueable;
    use Illuminate\Notifications\Notification;
    use Illuminate\Contracts\Queue\ShouldQueue;
    use Illuminate\Notifications\Messages\MailMessage;
    use App\Models\Reply;
    
    class TopicReplied extends Notification implements ShouldQueue
    {
        use Queueable;
    
        public $reply;
    
        public function __construct(Reply $reply)
        {
            // 注入回复实体,方便 toDatabase 方法中的使用
            $this->reply = $reply;
        }
    
        public function via($notifiable)
        {
            // 开启通知的频道
            return ['database', 'mail'];
        }
    
        public function toDatabase($notifiable)
        {
            $topic = $this->reply->topic;
            $link =  $topic->link(['#reply' . $this->reply->id]);
    
            // 存入数据库里的数据
            return [
                'reply_id' => $this->reply->id,
                'reply_content' => $this->reply->content,
                'user_id' => $this->reply->user->id,
                'user_name' => $this->reply->user->name,
                'user_avatar' => $this->reply->user->avatar,
                'topic_link' => $link,
                'topic_id' => $topic->id,
                'topic_title' => $topic->title,
            ];
        }
    
        public function toMail($notifiable)
        {
            $url = $this->reply->topic->link(['#reply' . $this->reply->id]);
    
            return (new MailMessage)
                        ->line('你的话题有新回复!')
                        ->action('查看回复', $url);
        }
    }
    
  • 创建 LaraBBS 应用时报错 Composer\Repository\RepositorySecurityException 怎么解决? at 9个月前

    @Summer 换了镜像后试过没有问题。感谢快速响应!