标签:
namespace App\Providers; class EventServiceProvider extends ServiceProvider { protected $listen = [ ‘App\Events\UserHasRegistered‘ => [ //修改event ‘App\Listeners\Email@welcome‘, //修改listener,Email是类名,welcome是函数名 ], ];
E:\wamp\www\laravel>php artisan event:generate
Route::get(‘broadcast‘, function () { event(new App\Events\UserHasRegistered(‘Jeffrey Way‘)); });
namespace App\Events; class UserHasRegistered extends Event { use SerializesModels; public $name; public function __construct($name) { $this->name = $name; }
namespace App\Listeners; class Email { public function __construct() { // } public function handle(UserHasRegistered $event) { var_dump(‘The user ‘.$event->name . ‘ has registered. Fire off an email.‘); //可以调用到name参数 }
标签:
原文地址:http://www.cnblogs.com/fenle/p/4806819.html