我正在使用Tinker测试Laravel广播事件。每次我更改代码源时,都必须重新启动修补程序才能生效。
App \ Events \ ShippingStatusUpdated.php
<?php
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class ShippingStatusUpdated implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $update;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct($update)
{
$this->update = $update;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new Channel('order-5');
}
public function broadcastWith() {
return ['status' => $this->update];
}
}
resources \ bootstrap.js
//...
import Echo from 'laravel-echo';
window.Pusher = require('pusher-js');
window.Echo = new Echo({
broadcaster: 'pusher',
key: process.env.MIX_PUSHER_APP_KEY,
cluster: process.env.MIX_PUSHER_APP_CLUSTER,
encrypted: true
});
let orderId = 5;
window.Echo.channel(`order-${orderId}`)
.listen('ShippingStatusUpdated', (e) => {
console.log(e);
});
预览
*第一次尝试:代码更改(将construct
添加到ShippingStatusUpdated
calass)和相同的Tinker实例:获取(status: null
)
*第二次尝试重新启动Tinker后:得到(status: 3
)
为什么会发生这种情况,以及如何迫使Tinker考虑代码源更改?