BookStack/app/Entities/Models/EntityScope.php
Dan Brown c767ddedb8
Some checks failed
analyse-php / build (push) Has been cancelled
lint-php / build (push) Has been cancelled
test-migrations / build (8.2) (push) Has been cancelled
test-migrations / build (8.3) (push) Has been cancelled
test-migrations / build (8.4) (push) Has been cancelled
test-php / build (8.2) (push) Has been cancelled
test-php / build (8.3) (push) Has been cancelled
test-php / build (8.4) (push) Has been cancelled
DB: Got most view queries working for new stucture
2025-09-19 15:38:00 +01:00

28 lines
930 B
PHP

<?php
namespace BookStack\Entities\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Scope;
use Illuminate\Database\Query\JoinClause;
class EntityScope implements Scope
{
/**
* Apply the scope to a given Eloquent query builder.
*/
public function apply(Builder $builder, Model $model): void
{
$builder = $builder->where('type', '=', $model->getMorphClass());
if ($model instanceof Page) {
$builder->leftJoin('entity_page_data', 'entity_page_data.page_id', '=', 'entities.id');
} else {
$builder->leftJoin('entity_container_data', function (JoinClause $join) use ($model) {
$join->on('entity_container_data.entity_id', '=', 'entities.id')
->where('entity_container_data.entity_type', '=', $model->getMorphClass());
});
}
}
}