我创建了一个名为的事件UserWalletNewTransaction.php
并将其添加到其中:
public $transaction;
public function __construct($transaction) {
$this->$transaction = $transaction;
}
并在以下位置注册EventServiceProivder.php
:
use App\Listeners\UserWalletNotification;
protected $listen = [
UserWalletNewTransaction::class => [
UserWalletNotification::class,
],
现在为了在控制器上触发这个事件,我编写了这个代码:
$newTransaction = UserWalletTransaction::create(['user_id' => $user_id, 'wallet_id' => $wallet_id, 'creator_id' => $creator_id, 'amount' => $amount_add_value, 'description' => $trans_desc]);
event(new UserWalletNewTransaction($newTransaction));
然后在听众处UserWalletNotification.php
,我尝试了:
public function handle(UserWalletNewTransaction $event) {
$uid = $event->user_id;
dd($uid);
}
但我收到Undefined property: App\Events\UserWalletNewTransaction::$user_id
错误消息。
但是,如果我尝试dd($event)
,这个结果会成功出现:
那么这里出了什么问题?我怎样才能得到user_id
已经存在的那个$event
?
我真的很感激你们的任何想法或建议......