D:\phpStudy\WWW\BCCKidV1.0\vendor\laravel\framework\src\Illuminate\Auth\Notifications\ResetPassword.php
创建通知:
php artisan make:notification UserRegister
指定发送提醒的方式:
public function via($notifiable)
{
return $notifiable->prefers_sms ? ['nexmo'] : ['mail', 'database'];
}
使用队列发送邮件:
class InvoicePaid extends Notification implements ShouldQueue
{
use Queueable;
....
在需要发送邮件提醒的用户里面use Notifiable这个trait:
<?php
namespace App\Models;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use SMartins\PassportMultiauth\HasMultiAuthApiTokens;
use Spatie\Permission\Traits\HasRoles;
class ChannelUser extends Authenticatable
{
use HasRoles;
use Notifiable, HasMultiAuthApiTokens;
}
单人提醒:
use App\Notifications\InvoicePaid;
$user->notify(new InvoicePaid($invoice));
使用Notification facde 进行批量(多个收件人)发送邮件提醒:
Notification::send($users, new InvoicePaid($invoice));
延时发送:
$when = now()->addMinutes(10);
$user->notify((new InvoicePaid($invoice))->delay($when));
如果要使用邮件功能的人不在user表里面,那么就使用如下方法:
Notification::route('mail', 'taylor@laravel.com')
->route('nexmo', '5555555555')
->notify(new InvoicePaid($invoice));