plank/publisher

View on GitHub
src/Scopes/PublisherScope.php

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
<?php

namespace Plank\Publisher\Scopes;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Scope;
use Plank\Publisher\Builders\PublisherBuilder;
use Plank\Publisher\Facades\Publisher;

class PublisherScope implements Scope
{
    /**
     * Apply the scope to a given Eloquent query builder.
     *
     * @param  PublisherBuilder  $builder
     * @return void
     */
    public function apply(Builder $builder, Model $model)
    {
        if (Publisher::draftContentRestricted()) {
            $builder->onlyPublished();
        } else {
            $builder->withoutQueuedDeletes();
        }
    }
}