我的应用中有多个通知,其中大部分都在工作,但其中一个收到此错误:
laravel Notification is missing toDatabase / toArray method . at /var/www/vendor/laravel/framework/src/Illuminate/Notifications/Channels/DatabaseChannel.php:44
代码:
<?php
namespace App\Notifications\Notifications\NotifyBrand\Campaign;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class AfterCreateCampaignNotif extends Notification implements ShouldQueue
{
use Queueable;
public function __construct()
{
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['mail','database'];
}
public function toMail($notifiable)
{
return (new MailMessage)
->subject('subject')
->view('Emails.Template1',
[
'BigTitle' => '...'
]);
}
public function toArray($notifiable)
{
return [
'title' => '...'
];
}
}
我尝试用 toDatabase 替换 toArray 但没有任何改变 我使用的是 Laravel 6.20.3,我的数据库是 Mysql 7.4.1