3 namespace BookStack\Entities\Models;
5 use Illuminate\Database\Eloquent\Builder;
6 use Illuminate\Database\Query\Builder as QueryBuilder;
8 class EntityQueryBuilder extends Builder
11 * Create a new Eloquent query builder instance.
13 public function __construct(QueryBuilder $query)
15 parent::__construct($query);
17 $this->withGlobalScope('entity', new EntityScope());
20 public function withoutGlobalScope($scope): static
22 // Prevent removal of the entity scope
23 if ($scope === 'entity') {
27 return parent::withoutGlobalScope($scope);
31 * Override the default forceDelete method to add type filter onto the query
32 * since it specifically ignores scopes by default.
34 public function forceDelete()
36 return $this->query->where('type', '=', $this->model->getMorphClass())->delete();