我创建了一个侦听器,在创建新用户时更新数据库中的字段。这是我的事。
class NewUser
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $user;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct(User $user)
{
$this->user = $user;
}
/**
* Get the channels the event should broadcast on.
*
* @return Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('channel-name');
}
}
和我的听众
public function handle(NewUser $event)
{
$captainrefid = DB::table('users')->where('referral_id', $event->user->referred_by)->value('referral_id');
$capdownlnrs = DB::table('users')->where('upliner', $captainrefid)->get();
if(count($capdownlnrs) > 2){
return DB::table('users')->where('id', $event->user->id)->update(['upliner' => $captainrefid]);
}
这是我的活动服务提供商
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Event;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as
ServiceProvider;
class EventServiceProvider extends ServiceProvider
{
/**
* The event listener mappings for the application.
*
* @var array
*/
protected $listen = [
'App\Events\NewUser' => [
'App\Listeners\UserPairingAndSpillover',
],
];
/**
* Register any events for your application.
*
* @return void
*/
public function boot()
{
parent::boot();
//
}
}
它是在用户模型中注册的。
protected $events = [
'created' => Events\NewUser::class
];
但它没有给出任何错误。然而,列我们数据库没有更新。任何人都可以帮助我为什么?我不必强制排队。