1.比如收到关注的时候的通知,同时发送通知邮件:
参考:
Learn How to Send Beautiful Mail Notifications in Laravel
Laravel 5.7 - New Notification System Tutorial for Beginner
系列讲解:
Laravel技巧集锦(29):使用vuejs组件化开发关注按钮
Laravel技巧集锦(31):使用vuejs组件化开发关注作者按钮
Laravel技巧集锦(32):使用notification实现站内通知(数据库)
Laravel技巧集锦(33):使用notification实现站内通知(邮件)
Laravel技巧集锦(34):使用vuejs组件化开发点赞按钮
Laravel技巧集锦(35):使用vuejs组件化开发发送私信功能
Laravel技巧集锦(39):使用notification实现站内通知(私信通知)
示例项目:
Laravel Notifications – The Ultimate Guide
扩展包:
使用Notification:
执行
1 php artisan make:notification NewUserFollowNotification再执行
1 php artisan notifications:table生成一个官方提供的notifications的数据库迁移文件
执行
1 php artisan migrate修改NewUserFollowNotification:
1 <?php 2 3 namespace App\Notifications; 4 5 use App\User; 6 use Illuminate\Bus\Queueable; 7 use Illuminate\Contracts\Queue\ShouldQueue; 8 use Illuminate\Notifications\Messages\MailMessage; 9 use Illuminate\Notifications\Notification; 10 11 class NewUserFollowNotification extends Notification 12 { 13 use Queueable; 14 /** 15 * @var User 16 */ 17 private $user; 18 19 /** 20 * Create a new notification instance. 21 * 22 * @param $user 23 */ 24 public function __construct($user) 25 { 26 // 27 $this->user = $user; 28 } 29 30 /** 31 * Get the notification's delivery channels. 32 * 33 * @param mixed $notifiable 34 * @return array 35 */ 36 public function via($notifiable) 37 { 38 return ['database']; 39 } 40 41 /** 42 * Get the mail representation of the notification. 43 * 44 * @param mixed $notifiable 45 * @return \Illuminate\Notifications\Messages\MailMessage 46 */ 47 public function toMail($notifiable) 48 { 49 return (new MailMessage) 50 ->line('The introduction to the notification.') 51 ->action('Notification Action', url('/')) 52 ->line('Thank you for using our application!'); 53 } 54 55 /** 56 * Get the array representation of the notification. 57 * 58 * @param mixed $notifiable 59 * @return array 60 */ 61 public function toArray($notifiable) 62 { 63 return [ 64 // 65 ]; 66 } 67 68 69 /** 70 * 添加一个方法,方法名要与via中添加的database 一致 to加上Database 71 * @param $notifiable 72 * @return array 73 */ 74 public function toDatabase($notifiable) 75 { 76 return [ 77 //要记录的数据 78 'name' => $this->user->name, 79 ]; 80 } 81 } 82 83