【问题标题】:How to solve Call to a member function notify() on array? (laravel 5.3)如何解决调用数组上的成员函数 notify()? (laravel 5.3)
【发布时间】:2017-01-13 00:54:57
【问题描述】:

我的听众是这样的:

<?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()

如何解决?

【问题讨论】:

  • 数组没有方法(成员函数)

标签: php laravel sendmail laravel-5.3


【解决方案1】:

您需要在具有Illuminate\Notifications\Notifiable 特征的模型上使用notify(),但绝对不能在数组上使用。

例如,您可以先获取User 的实例:

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

然后使用notify():

$user->notify(....)

【讨论】:

【解决方案2】:

好的,我试图向应用程序的最终用户发送电子邮件以激活他们的帐户(在注册表中提供)然后我收到此错误,因为我将“ID”传递给 notify(),实际上它应该传递整个用户的详细信息。

通过更改Http/Controller/Admin/Auth/RegistrationController.php解决

这就是我的通知类:app/Notification/UserActivate.php 看看我的

__construct() and toMail($notifiable) methods

希望我的错误对你有所帮助。 :)

【讨论】:

    猜你喜欢
    • 2017-05-04
    • 2021-03-20
    • 2017-04-08
    • 2017-03-10
    • 2021-07-20
    • 1970-01-01
    • 2017-10-03
    • 1970-01-01
    • 2022-01-22
    相关资源
    最近更新 更多