簡體   English   中英

如何解決對數組成員函數notify()的調用? (laravel 5.3)

[英]How to solve Call to a member function notify() on array? (laravel 5.3)

我的聽眾是這樣的:

<?php

namespace App\Listeners;

use App\Events\CheckoutOrderEvent;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Mail;

class CheckoutOrderListener
{
    public function __construct()
    {
        //
    }
    public function handle(CheckoutOrderEvent $event)
    {
        // dd($event);
        $event->data->notify(New \App\Notifications\CheckoutOrder($event->data));
    }
}

如果我運行 dd($event),結果是這樣的:

在此處輸入圖片說明

執行時,存在錯誤:調用數組上的成員函數notify()

如何解決?

您需要在具有Illuminate\\Notifications\\Notifiable特征的模型上使用notify() ,但絕對不能在數組上使用。

例如,您可以先獲取一個User的實例:

$user = User::where('email', $event->data['email'])->first();

然后使用notify()

$user->notify(....)

好的,我試圖向應用程序的最終用戶發送電子郵件以激活他們的帳戶(在注冊表中提供)然后我收到此錯誤,因為我將“ID”傳遞給 notify(),實際上它應該傳遞用戶的全部詳細信息. 在此處輸入圖片說明

通過在 Http/Controller/Admin/Auth/RegistrationController.php 中更改解決

在此處輸入圖片說明

這就是我的通知類:app/Notification/UserActivate.php 看看我的

__construct() and toMail($notifiable) methods

在此處輸入圖片說明

我希望我的錯誤對你有幫助。 :)

在 Laravel 8

[英]Call to a member function notify() on null in Laravel 8

如何在 laravel

[英]How to solve Call to a member function department() on bool in laravel

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM