在班级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
答案 0 :(得分:2)
removeFromLineupPrepare
是一种方法,但您正在像属性一样访问它。尝试:
$player->removeFromLineupPrepare();