我刚刚又去写了一遍代码,貌似还是没有什么错。不知道是我理解错你的意思还是?
1.UserSignUpListener(这是你说的监听类吧):
class UserSignUpListener
{
public $filesystem;
/**
* Create the event listener.
*
* @return void
*/
public function __construct(Filesystem $filesystem)
{
$this->filesystem = $filesystem;
}
/**
* Handle the event.
*
* @param UserSignUp $event
* @return void
*/
public function handle(UserSignUp $event)
{
var_dump($this->filesystem->get(public_path('robots.txt')));
}
2.UserSignUp (事件):
class UserSignUp
{
use 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');
}
3.使用 event() 触发:
$user = \App\User::find(8);
event(new \App\Events\UserSignUp($user));
我这里依然没有什么错,代码还是正常执行。
所以你的代码和报错具体是什么?