当模型更新按计划任务运行时,雄辩事件不会触发Laravel自定义事件

时间:2018-07-06 13:45:17

标签: laravel laravel-5

我有一个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
        ];
    }
}

有什么想法吗?

0 个答案:

没有答案