我有一个updated
雄辩的模型事件触发的自定义事件。当手动完成更新(即在计划任务之外)时,此自定义事件有效,但是在通过计划任务完成更新时,不
型号代码
<?php namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Location extends Model {
self::updated(function ($location) {
event(new LocationRefresh($location));
});
}
这是事件监听器:
<?php namespace App\Events;
use App\Events\Event;
use App\Models\Location;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class LocationRefresh extends Event implements ShouldBroadcast
{
use SerializesModels;
public $id;
public $closed;
public $closed_until;
public function __construct(Location $location)
{
$this->id = $location->id;
$this->closed = $location->closed;
$this->closed_until = $location->closed_until;
}
public function broadcastOn()
{
return [
'private-location-'.$this->id
];
}
}
有什么想法吗?