如何解决对数组成员函数notify()的调用?(laravel 5.3)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41625733/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to solve Call to a member function notify() on array? (laravel 5.3)
提问by moses toh
My listener is like this :
我的听众是这样的:
<?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));
}
}
If I run dd($event), the result is like this :
如果我运行 dd($event),结果是这样的:
When executed, there exist error : Call to a member function notify() on array
执行时,存在错误:调用数组上的成员函数notify()
How to solve it?
如何解决?
回答by Alexey Mezenin
You need to use notify()
on a model with Illuminate\Notifications\Notifiable
trait, but definitely not on an array.
您需要notify()
在具有Illuminate\Notifications\Notifiable
特征的模型上使用,但绝对不能在数组上使用。
For example, you can get an instance of a User
first:
例如,您可以获得 a User
first的实例:
$user = User::where('email', $event->data['email'])->first();
And then use notify()
:
然后使用notify()
:
$user->notify(....)
回答by Vipertecpro
Alright, I was trying to send email to end-user of the application for activating their account (Provided in registration form ) then i got this Error because i was passing "ID" to notify(), actually it should pass whole details of users.
好的,我试图向应用程序的最终用户发送电子邮件以激活他们的帐户(在注册表中提供)然后我收到此错误,因为我将“ID”传递给 notify(),实际上它应该传递用户的全部详细信息.
Solved By changing in Http/Controller/Admin/Auth/RegistrationController.php
通过在 Http/Controller/Admin/Auth/RegistrationController.php 中更改解决
And that's my Notification Class: app/Notification/UserActivate.php Look at my
这就是我的通知类:app/Notification/UserActivate.php 看看我的
__construct() and toMail($notifiable) methods
__construct() and toMail($notifiable) methods
I hope my mistake helped you. :)
我希望我的错误对你有帮助。:)