Example of Global scopes in guillaumebriday/laravel-blog

File master/app/Scopes/PostedScope.php (link to Github)
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Scope;
use Illuminate\Support\Facades\Auth;

class PostedScope implements Scope
{
    public function apply(Builder $builder, Model $model): void
    {
        $user = Auth::user() ?? Auth::guard('api')->user();

        if (!$user || !$user->isAdmin()) {
            $builder->where('posted_at', '<=', now());
        }
    }
}
File app/Models/Post.php (link to Github)
use App\Scopes\PostedScope;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    protected static function boot(): void
    {
        parent::boot();
        static::addGlobalScope(new PostedScope);
    }
{

Additional resources on global scopes: