Laravel功能无需返回

时间:2017-09-19 11:12:53

标签: laravel laravel-5

在班级Player我有方法:

public function removeFromLineupPrepare()
{
    if (isset($this->team->lineupPrepare) &&$this->lineupPreparePosition) {
        $this->team->lineupPrepare->update([
            $this->lineupPreparePosition => NULL
        ]);
    }
}

当我使用上述方法时:

if ($player->team && $request->team_id != $player->team_id) {
        $player->removeFromLineupPrepare;
}

我收到了一个错误:

Relationship method must return an object of type Illuminate\Database\Eloquent\Relations\Relation

1 个答案:

答案 0 :(得分:2)

removeFromLineupPrepare是一种方法,但您正在像属性一样访问它。尝试:

$player->removeFromLineupPrepare();