master/app/Scopes/PostedScope.php
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()); } }}