laravel数据库通知

时间:2017-03-15 05:36:38

标签: laravel laravel-5 notifications

我想使用laravel数据库通知,在我创建通知类并放入代码之后迁移通知表

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Messages\DatabaseMessage;

class CampaignNotify extends Notification
{
    use Queueable;

    public $name;
    public $campa_id;
    public $campa_name;
    /**
     * Create a new notification instance.
     *
     * @return void
     */
      public function __construct($name, $campa_id,$campa_name) {
        $this->name = $name;
        $this->campa_id = $campa_id;
        $this->campa_name = $campa_name;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['database'];
    }

    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        return (new MailMessage)
                    ->subject('GoDutch :: Your Campaign is created')
                    ->greeting('Dear '.$this->name.',')
                    ->line('You are receiving this email because your campaign "'.$this->campa_name.'" is created. Click the button below to checkout')
                    ->action('check Campaign', Route('user.home'))
                    ->line('Thank you for using our application!');
    }

    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            'trainee_id' => 'cancelled'
        ];
    }
}

调用此通知后我收到错误,邮件通道工作正常,但数据库给出错误

QueryException in Connection.php line 770:
Array to string conversion (SQL: insert into `notifications` (`type`, `data`, `read_at`, `updated_at`, `created_at`) values (App\Notifications\CampaignNotify, cancelled, , 2017-03-14 18:05:56, 2017-03-14 18:05:56))
in Connection.php line 770
at Connection->runQueryCallback('insert into `notifications` (`type`, `data`, `read_at`, `updated_at`, `created_at`) values (?, ?, ?, ?, ?)', array('App\Notifications\CampaignNotify', array('trainee_id' => 'cancelled'), null, '2017-03-14 18:05:56', '2017-03-14 18:05:56'), object(Closure)) in Connection.php line 726
at Connection->run('insert into `notifications` (`type`, `data`, `read_at`, `updated_at`, `created_at`) values (?, ?, ?, ?, ?)', array('App\Notifications\CampaignNotify', array('trainee_id' => 'cancelled'), null, '2017-03-14 18:05:56', '2017-03-14 18:05:56'), object(Closure)) in Connection.php line 481
at Connection->statement('insert into `notifications` (`type`, `data`, `read_at`, `updated_at`, `created_at`) values (?, ?, ?, ?, ?)', array('App\Notifications\CampaignNotify', array('trainee_id' => 'cancelled'), null, '2017-03-14 18:05:56', '2017-03-14 18:05:56')) in Connection.php line 435
at Connection->insert('insert into `notifications` (`type`, `data`, `read_at`, `updated_at`, `created_at`) values (?, ?, ?, ?, ?)', array('App\Notifications\CampaignNotify', array('trainee_id' => 'cancelled'), null, '2017-03-14 18:05:56', '2017-03-14 18:05:56')) in Processor.php line 32
at Processor->processInsertGetId(object(Builder), 'insert into `notifications` (`type`, `data`, `read_at`, `updated_at`, `created_at`) values (?, ?, ?, ?, ?)', array('App\Notifications\CampaignNotify', array('trainee_id' => 'cancelled'), null, '2017-03-14 18:05:56', '2017-03-14 18:05:56'), 'id') in Builder.php line 2154
at Builder->insertGetId(array('App\Notifications\CampaignNotify', array('trainee_id' => 'cancelled'), null, '2017-03-14 18:05:56', '2017-03-14 18:05:56'), 'id') in Builder.php line 1470
at Builder->__call('insertGetId', array(array('type' => 'App\Notifications\CampaignNotify', 'data' => array('trainee_id' => 'cancelled'), 'read_at' => null, 'updated_at' => '2017-03-14 18:05:56', 'created_at' => '2017-03-14 18:05:56'), 'id')) in Model.php line 1609
at Model->insertAndSetId(object(Builder), array('type' => 'App\Notifications\CampaignNotify', 'data' => array('trainee_id' => 'cancelled'), 'read_at' => null, 'updated_at' => '2017-03-14 18:05:56', 'created_at' => '2017-03-14 18:05:56')) in Model.php line 1574
at Model->performInsert(object(Builder)) in Model.php line 1471
at Model->save(array('touch' => false)) in BelongsToMany.php line 773

0 个答案:

没有答案