Laravel事件系统的运行原理怎样理解,过程是怎样
Admin 2022-06-15 群英技术资讯 478 次浏览
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。
在本文中,我会向你展示如何在 Laravel 中从头开始实现 repository 设计模式。我将使用 Laravel 5.8.3 版,但 Laravel 版本不是最重要的。在开始写代码之前,你需要了解一些关于 repository 设计模式的相关信息。
这篇文章主要介绍了在 Laravel 中动态隐藏 API 字段的方法,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下
在网站功能建设中,php随机数是常用的一个功能,比如用户注册时随机产生的验证码、又比如用户注册时生成随机的一组密码后可自行修改,当用户需要重置密码的时候也需要生成一个随机的密码······随机数就根据特定的规则(或在一个数组范围内)所自动产生的字符串,在php开发中应用广泛,不过php中的随机数也分好几种不同的情况,首先来认识一下PHP提供的随机数函数rand()。
PHP日期和时间函数怎么用?常用的时间函数有哪些?对于PHP初学者来说,可能对于日期与时间函数不是很清楚,因此,这篇文章就给大家介绍常用的时间函数及用法,有需要的朋友可以参考学习。
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008