【发布时间】:2020-03-03 14:24:53
【问题描述】:
我正在使用 laravel 并使用通知系统
所以我在通知表中添加一列“URL”并希望将其存储在数据库中,但它不起作用,我真的不知道如何添加字段并存储在数据库中
这是我的通知类,并在提交新评论时通知:
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
class NewComment extends Notification
{
use Queueable;
private $details;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct($details)
{
$this->details = $details;
}
/**
* 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)
{
//
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
'message' => $this->details['message'],
'product' => $this->details['product'],
'url' => 'test'
];
}
}
这里是控制器
$details = [
'message' => 'یک نظر جدید برای محصول',
'product' => $product->title
];
$user->notify(new NewComment($details));
它给了我这个错误:
一般错误:1364 字段 'url' 没有默认值
【问题讨论】:
标签: php laravel notifications