【发布时间】:2019-09-19 11:59:32
【问题描述】:
我正在尝试为用户设置通知。但是当我的方法尝试在我的 RequestinfoController 中将数据设置到数据库中时,它总是发送 null:user_id 有值
Xampp PHP 版本 7.2.5 阿帕奇/2.4.33 Laravel 5.5
/* Controller */
public function acceptRequest($employer_id, $user_id)
{
$requestinfo = Requestinfo::where(['employer_id'=> $employer_id, 'user_id'=>$user_id])->first();
$employer = Employer::find($employer_id);
$requestinfo->update(['accepted'=> 1]);
if($requestinfo){
$employer->notify(new AcceptedRequest($user_id));
return alert_msg('success', 'update_success' ,'requestinfo');
}
return alert_msg('error', 'update_error' ,'requestinfo');
}
这是通知代码
/* Notification */
class AcceptedRequest extends Notification
{
use Queueable;
public $user_id;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct($user_id)
{
$this->$user_id = $user_id;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['database'];
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
"user_id"=> $this->user_id,
"message"=> "request info accepted",
"icon"=> "<i class='fas fa-check-square'></i>"
];
}
}
//结果在数据库中
{"user_id":null,"message":"已接受请求信息","icon":""}
【问题讨论】:
标签: laravel notifications laravel-5.5