Laravel 中的队列调度方法抛出错误

Queues Dispatch method in Laravel Throws error

所以这是我的代码行

public function getVisitedCountriesCountAttribute()
{
    $this->dispatch(new CalculateTotalCountriesVisited($this));

    return $this->total_countries;
}

这里的 dispatch 方法抛出一个错误

Call to undefined method Illuminate\Database\Query\Builder::dispatch() (View: /Users/mereeva/sites/rdb-ws/resources/views/users/trips/status.blade.php)

我似乎不明白这背后的原因是什么。我遵循了 https://laravel.com/docs/5.1/queues

中的所有步骤

如有任何帮助,我们将不胜感激。谢谢

如果你想从你的模型中调度你必须在其中使用特征Illuminate\Foundation\Bus\DispatchesJobs;,否则你将无法做到$this->dispatch(...

不使用此特性的另一种方法是使用调度助手:

dispatch(new CalculateTotalCountriesVisited($this));

这会自动从应用程序容器中解析 Dispatcher。