在HomeController.php我发送这样的通知$user->notify(new OutdatedAELocation($conSite));
然后在OutdatedAELocation.php我尝试使用此数据将通知存储到数据库中。
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class OutdatedAELocation extends Notification implements ShouldQueue
{
use Queueable;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct($conSite)
{
$this->CSid = $conSite->id;
$this->outdatedAes = $conSite->outdatedAes;
$this->link = $conSite->link;
}
/**
* 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)
{
// dd($this);
return [
'conSite_id' => $this->CSid,
'outdatedAes' => $this->outdatedAes,
'link' => $this->link,
];
}
}
由于某种原因,数据不会传给toArray方法。
当我dd($this)在 __construct() 方法末尾调用时,它就在那里:
App\Notifications\OutdatedAELocation {#1329 ▼
+id: null
+locale: null
+connection: null
+queue: null
+chainConnection: null
+chainQueue: null
+delay: null
+middleware: []
+chained: []
+"CSid": 1
+"outdatedAes": "info, "
+"link": "https://app.com/query?location=1"
}
但是,当我dd($this)在方法的第一行调用时toArray(),是这样的:
App\Notifications\OutdatedAELocation {#1780 ▼
+id: "ac659b25-7ff2-4500-adc8-72e6508d50c6"
+locale: null
+connection: null
+queue: null
+chainConnection: null
+chainQueue: null
+delay: null
+middleware: []
+chained: []
}
请问,如何传递数据?
吃鸡游戏