use BookStack\Auth\Permissions\PermissionApplicator;
use BookStack\Entities\Models\Entity;
use BookStack\Entities\Models\Page;
+use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Relations\Relation;
*/
public function getPageReferencesToEntity(Entity $entity): Collection
{
- $baseQuery = $entity->referencesTo()
- ->where('from_type', '=', (new Page())->getMorphClass())
+ $baseQuery = $this->queryPageReferencesToEntity($entity)
->with([
'from' => fn (Relation $query) => $query->select(Page::$listAttributes),
'from.book' => fn (Relation $query) => $query->scopes('visible'),
*/
public function getPageReferenceCountToEntity(Entity $entity): int
{
- $baseQuery = $entity->referencesTo()
- ->where('from_type', '=', (new Page())->getMorphClass());
-
$count = $this->permissions->restrictEntityRelationQuery(
- $baseQuery,
+ $this->queryPageReferencesToEntity($entity),
'references',
'from_id',
'from_type'
return $count;
}
+
+ protected function queryPageReferencesToEntity(Entity $entity): Builder
+ {
+ return Reference::query()
+ ->where('to_type', '=', $entity->getMorphClass())
+ ->where('to_id', '=', $entity->id)
+ ->where('from_type', '=', (new Page())->getMorphClass());
+ }
}