table) ->where($this->primaryKeyColumn, '=', $id) ->when($parentId !== null, fn (Builder $query) => $query->where($this->getParentColumn(), $parentId)) ->exists(); } /** * Get an object. * * Optionally, pass the ID of a parent entity to only get an object * if it exists and is assigned to that parent. * * @return ?T */ public function get(int $id, int $parentId = null): ?DataObject { $row = DB::table($this->table) ->where($this->primaryKeyColumn, $id) ->when($parentId !== null, fn (Builder $query) => $query->where($this->getParentColumn(), $parentId)) ->first(); return $row ? $this->fromRow($row) : null; } }