'highlight_id', 'contextId' => 'context_id', 'sequence' => 'sequence', 'url' => 'url', ]; /** * Instantiate a new Highlight */ public function newDataObject(): Highlight { return app(Highlight::class); } /** * Check if a highlight exists */ public function exists(int $id, ?int $contextId): bool { return DB::table($this->table) ->where($this->primaryKeyColumn, $id) ->where($this->parentKeyColumn, $contextId) ->exists(); } /** * Get a highlight */ public function get(int $id, ?int $contextId): ?Highlight { $row = DB::table($this->table) ->where($this->primaryKeyColumn, $id) ->where($this->parentKeyColumn, $contextId) ->first(); return $row ? $this->fromRow($row) : null; } /** * Get the number of highlights matching the configured query */ public function getCount(Collector $query): int { return $query ->getQueryBuilder() ->get('a.' . $this->primaryKeyColumn) ->count(); } /** * Get a list of ids matching the configured query * * @return Collection */ public function getIds(Collector $query): Collection { return $query ->getQueryBuilder() ->pluck('a.' . $this->primaryKeyColumn); } /** * Get a collection of highlights matching the configured query * * @return LazyCollection */ public function getMany(Collector $query): LazyCollection { $rows = $query ->getQueryBuilder() ->get(); return LazyCollection::make(function () use ($rows) { foreach ($rows as $row) { yield $row->highlight_id => $this->fromRow($row); } }); } public function insert(Highlight $highlight): int { return parent::_insert($highlight); } public function update(Highlight $highlight) { parent::_update($highlight); } public function delete(Highlight $highlight) { parent::_delete($highlight); } /** * Get the largest sequence value for a given context */ public function getLastSequence(?int $contextId = null): ?int { return DB::table($this->table) ->when( $contextId, fn($qb) => $qb->where('context_id', $contextId), fn($qb) => $qb->whereNull('context_id') ) ->orderBy('sequence', 'desc') ->first('sequence') ?->sequence; } }