namespace app\events;
class Test
{
public $data = [];
public function __construct($data)
{
$this->data = $data;
}
}
监听类
namespace app\listeners;
use app\events\Test;
class TestListeners
{
public function __construct()
{
}
/**
* 处理事件
* @return void
*/
public function handle(Test $event)
{
// 控制台打印
var_dump('listener');
var_dump($event->data);
}
}
订阅类
namespace app\subscribes;
use app\events\Test;
class TestSubscribe
{
public function handleTest(Test $event)
{
var_dump('subscribe');
var_dump($event);
}
public function subscribe($events)
{
$events->listen(
Test::class,
[TestSubscribe::class, 'handleTest']
);
}
}
https://www.workerman.net/a/1261
评论里有使用laravel 事件库的
谢谢大佬
laravel event事件使用
配置
config/events.php
事件类:Test
监听类
订阅类
helpers.php 增加
调用触发事件
谢谢大佬