在HomeController.php我發(fā)送這樣的通知$user->notify(new OutdatedAELocation($conSite));然后在OutdatedAELocation.php我嘗試使用此數(shù)據(jù)將通知存儲(chǔ)到數(shù)據(jù)庫(kù)中。<?phpnamespace 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, ]; }}由于某種原因,數(shù)據(jù)不會(huì)傳給toArray方法。當(dāng)我dd($this)在 __construct() 方法末尾調(diào)用時(shí),它就在那里: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"}但是,當(dāng)我dd($this)在方法的第一行調(diào)用時(shí)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: []}請(qǐng)問(wèn),如何傳遞數(shù)據(jù)?
1 回答

吃雞游戲
TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超7個(gè)贊
首先你必須定義類中的成員:
<?php
class OutdatedAELocation extends Notification implements ShouldQueue
{
use Queueable;
// HERE you define the members
var $CSid;
var $outdatedAes;
var $link;
// ...
}
之后dd($conSite);在構(gòu)造函數(shù)的開(kāi)頭嘗試查看是否將完整對(duì)象傳遞給類。
- 1 回答
- 0 關(guān)注
- 108 瀏覽
添加回答
舉報(bào)
0/150
提交
取消