laravel 通知缺少 toDatabase / toArray 方法

时间:2020-12-21 09:47:05

标签: php mysql laravel notifications

我的应用中有多个通知,其中大部分都在工作,但其中一个收到此错误:

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

0 个答案:

没有答案
相关问题