在EventServiceProvide文件里注册事件和监听

protected $listen = [
'App\Events\SendPhoneCodeEvent' => [
'App\Listeners\SendPhoneCodeListener',
]
];

1.建立事件文件Events/SendPhoneCodeEvent.php

<?php
namespace App\Events; class SendPhoneCodeEvent
{
use SerializesModels; public $data; /**
* 创建一个事件实例。
*
* @param \App\Order $order
* @return void
*/
public function __construct($data)
{
$this->data = $data;
}
}

2.建立监听文件 Listeners/SendPhoneCodeListener.php

<?php
namespace App\Listeners; use App\Events\SendPhoneCodeEvent;
use Illuminate\Support\Facades\Log; class SendPhoneCodeListener
{
/**
* 创建事件监听器。
*
* @return void
*/
public function __construct()
{ } /**
* 处理事件。
*
* @param \App\Events\SendPhoneCodeEvent $event
* @return void
*/
public function handle(SendPhoneCodeEvent $event)
{ Log::info("Listener:".$event->data);
} public function failed()
{
}
}

4.有控制器里调用事件

use App\Events\SendPhoneCodeEvent;

event(new SendPhoneCodeEvent(''));

最新文章

  1. 30分钟让网站支持HTTPS
  2. 求助sublime snippet
  3. 虚析构函数(√)、纯虚析构函数(√)、虚构造函数(X)
  4. 在EF的code frist下写稳健的权限管理系统:仓储设计(三)
  5. 用MSBuild和Jenkins搭建持续集成环境(2)
  6. web.xml中servlet初始化参数的设置
  7. HeadFirst设计模式之代理模式
  8. poj 1696 Space Ant(模拟+叉积)
  9. 一个简单的shell脚本
  10. Error with mysqld_safe
  11. MySQL TIMESTAMP(时间戳)详解
  12. JSP page指令
  13. 7种方法解决移动端Retina屏幕1px边框问题
  14. java枚举类(enum) 基础知识讲解
  15. Django之路由分发系统
  16. 不错的东西: AutoMapper
  17. c# 获取 com 引用真实组件地址
  18. 3,postman的变量写法和collection
  19. Yii的操作提示框
  20. 近几年ACM/ICPC区域赛铜牌题

热门文章

  1. -- 1 -- springboot
  2. WDS无人参与批量部署Ser 2008
  3. vue 安装插件
  4. springboot中的参数传递
  5. CentOS7利用systemctl添加dotnet后台服务
  6. React 工程的 VS Code 插件及配置
  7. 如何爬取icourse163 中国慕课上课程信息(上),
  8. ThreeJS 3d模型简介
  9. Spring Cloud(八)高可用的分布式配置中心 Spring Cloud Config
  10. Python学习记录3-函数参数详解