public function applyScopes()
{
if (!$this->scopes) {
return $this;
}
$builder = clone $this;
foreach ($this->scopes as $scope) {
$builder->callScope(function (Builder $builder) use($scope) {
if ($scope instanceof Closure) {
$scope($builder);
} elseif ($scope instanceof Scope) {
$scope->apply($builder, $this->getModel());
}
});
}
return $builder;
}