我正在尝试使用更新事件将所有模型更改推送到前端。我不想发送整个模型,所以我找到了hasChanges()
方法。但它总是空的。
我的第一个想法是这个事件在实际保存之前触发,但getDirty()
也是空的。然后我在调试栏中认为,由于某种原因,它在更新模型后立即再次检索模型(从数据库中选择)。这是正常行为还是只是创建一个新的模型对象而不将现有模型对象传递给事件?
事件:
class IcUpdated implements ShouldBroadcastNow
{
use Dispatchable, InteractsWithSockets, SerializesModels;
private $ic;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct($ic)
{
$this->ic = $ic;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return [
new Channel('dashboard_' . ConfigHelper::getSelectedOrganizationId())
];
}
public function broadcastAs()
{
return 'ic.updated';
}
public function broadcastWith()
{
return $this->ic->getChanges();
}
} …
Run Code Online (Sandbox Code Playgroud)