Laravel作业失败,使用模型范围

时间:2019-04-03 08:57:30

标签: laravel-queue laravel-5.8 laravel-jobs

我有一个具有范围的模型

public function scopeWithSets($query)
{
    return $query->with([
        'games.playerA.user',
        'games.playerB.user',
        'games.sets' => function ($relatedSets) {
            /**
             * @var \Illuminate\Database\Eloquent\Builder $relatedSets
             */
            $relatedSets->where('points_a', '>', 0)->orWhere('points_b', '>', 0);
        },
        'games' => function ($relatedGames) {
            /**
             * @var \Illuminate\Database\Eloquent\Builder $relatedGames
             */
            $relatedGames->whereNotNull('player_a_id')->orWhereNotNull('player_b_id');
        }]);
}

在类实例之后,在内部构造中,我从具有该范围的数据库中获取了一些数据

/**
 * @param GameSerie $gameSerie
 * @see GameSerie::scopeWithSets()
 */
public function __construct(GameSerie $gameSerie)
{
    $this->gameSerie = $gameSerie;

    $gameSerieData = GameSerie::select([
        'game_series.id',
        'team_a_id',
        'team_b_id',
        'championship_id',
        'count_wins_a',
        'count_wins_b'
    ])->where('id', $gameSerie->id)->withSets()->first();

    $this->data = $this->createStatisticCollection($gameSerieData);
}

如果我使用laravel tinker或通过API进行此操作,一切都很好。

我必须使用队列来完成任务,但是在分派工作后我的工作失败了。当我查看laravel.log时,我看到了

[2019-04-03 08:46:31] local.ERROR: Call to undefined method Illuminate\Database\Eloquent\Builder::withSets() {"exception":"[object] (BadMethodCallException(code: 0): Call to undefined method Illuminate\\Database\\Eloquent\\Builder::withSets() at /home/vagrant/code/fntr/vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php:50)

我将Redis用于队列。

0 个答案:

没有答案