Laravel事件系统的运行原理怎样理解,过程是怎样
Admin 2022-06-15 群英技术资讯 660 次浏览
protected $listen = [ Registered::class => [ SendEmailVerificationNotification::class, ], 'App\Events\Test' => [ 'App\Listeners\EventListener', ], ];
$ php artisan event:generate
<?php namespace App\Events;use App\Models\User;use Illuminate\Broadcasting\Channel;use Illuminate\Broadcasting\InteractsWithSockets;use Illuminate\Broadcasting\PresenceChannel;use Illuminate\Broadcasting\PrivateChannel;use Illuminate\Contracts\Broadcasting\ShouldBroadcast;use Illuminate\Foundation\Events\Dispatchable;use Illuminate\Queue\SerializesModels;class Test{ use Dispatchable, InteractsWithSockets, SerializesModels; /** * Create a new event instance. * * @return void */ public function __construct($id) { echo '触发事件成功!---------'.$id; $this->id = $id; } /** * Get the channels the event should broadcast on. * * @return \Illuminate\Broadcasting\Channel|array */ public function broadcastOn() { return new PrivateChannel('channel-name'); }}
<?php namespace App\Listeners; use App\Events\Test;use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Queue\InteractsWithQueue; class EventListener{ /** * Create the event listener. * * @return void */ public function __construct() { // } public function handle(Test $event) { echo '监听成功!监听值:'.$event->id; }}
public function test1(){ event(new Test('11111111')); return '测试事件系统';}
php artisan event:generate php artisan make:event UserRegisteredEvent php artisan make:listener SendMailListener --event="UserRegisteredEvent"
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
php中str_replace的替换:1、以字符替换字符串中的一些字符;2、语法str_replace(find,replace,string,count);3、参数Find、replace、string、count。
很多时候我们需要将几个字符串连接起来显示,在PHP中,字符串之间使用“点”来连接,也就是英文中的半角句号 "." 。"."是字符串连接符,可以把两个或两个以上的字符串链接成一个字符串。例如: 12345<?php$name = "PHP中文网:";$url = "www.php";echo $name . $url . ".cn";
今天小编就为大家分享一篇laravel 关联关系遍历数组的例子,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
1、使用header()设置过期时间。2、使用header()设置页面的最后更新日期为当天,可以强制浏览器获取最新资料。3、使用header()告诉客户端浏览器不使用缓存。
本文实例讲述了Thinkphp 框架扩展之标签库驱动原理与用法。下文有详细的介绍,小编觉得挺实用的,对大家学习或工作或许有帮助,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008