zoukankan      html  css  js  c++  java
  • Laravel 5.8 做个知乎 16 —— 用户关注 发送自定义的邮件通知

    1 新建频道

    1.1 appChannelsSendcloudChannel.php

    <?php
    /**
     * Created by PhpStorm.
     * User: SUN
     * Date: 2021/8/1
     * Time: 3:42
     */
    namespace AppChannels;
    
    use IlluminateNotificationsNotification;
    
    /**
     * 自定义channels
     */
    class SendcloudChannel
    {
        public function send($notifiable, Notification $notification)
        {
            $message = $notification->toSendcloud($notifiable,$notification);
        }
        
    }

    2 添加频道

    2.1 appNotificationsNewUserFollowNotinfication.php

    <?php
    
    namespace AppNotifications;
    
    
    use IlluminateBusQueueable;
    use IlluminateNotificationsNotification;
    use IlluminateContractsQueueShouldQueue;
    use IlluminateNotificationsMessagesMailMessage;
    use IlluminateSupportFacadesAuth;
    use IlluminateSupportFacadesMail;
    use NauxMailSendCloudTemplate;
    use AppChannelsSendcloudChannel;
    
    
    
    
    
    class NewUserFollowNotinfication extends Notification
    {
        use Queueable;
    
        /**
         * Create a new notification instance.
         *
         * @return void
         */
        public function __construct()
        {
            //
        }
    
        /**
         * Get the notification's delivery channels.
         *
         * @param  mixed  $notifiable
         * @return array
         */
        public function via($notifiable)
        {
            //        return ['mail'];   //邮件通知
            return ['database',SendcloudChannel::class]; //站内信
        }                      
        
        
        
        
      
        
        public function toSendcloud($notifiable)
        {
            //模板地址
            //https://www.sendcloud.net/email/#/sendAround/template
            $data = [
              'url' => url(config('app.url')),
              'name' => Auth::guard('api')->user()->name
            ];
            
            //test_template 邮件模板
            $template = new SendCloudTemplate('zhihu_app_new_user_follow',$data);
            Mail::raw($template,function ($message) use ($notifiable){
                $message->from(env('SEND_CLOUD_FROM'),'知乎管理员');
                $message->to($notifiable->email);
            });
        
        
        
            
            
            
        }
        
        public function toDatabase($notifiable)
        {
            return [
              'name'=> Auth::guard('api')->user()->name,
            
            ];
        }
    
        /**
         * Get the mail representation of the notification.
         *
         * @param  mixed  $notifiable
         * @return IlluminateNotificationsMessagesMailMessage
         */
        public function toMail($notifiable)
        {
            return (new MailMessage)
                        ->line('The introduction to the notification.')
                        ->action('Notification Action', url('/'))
                        ->line('Thank you for using our application!');
        }
    
        /**
         * Get the array representation of the notification.
         *
         * @param  mixed  $notifiable
         * @return array
         */
        public function toArray($notifiable)
        {
            return [
                //
            ];
        }
    }
    View Code

    3 添加邮件模板

  • 相关阅读:
    mysql索引
    mysql主从复制(同步)
    MySQL事务与锁
    四大高阶函数
    客户端、服务端通信值统计字符串个数【网络程序设计
    《Unicast QoS Routing Algorithms for SDN Survey 2018》【毕设
    CDQ分治【待补充,数据结构
    KD树学习小结【待补充,数据结构
    线段树模板【数据结构
    【牛客网】牛客练习赛19 F 算式子【数学--递推 、前缀、数字】
  • 原文地址:https://www.cnblogs.com/polax/p/15088291.html
Copyright © 2011-2022 走看看