-
master/app/Scopes/PostedScope.php
Open in GitHubuse 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()); } } }
-
app/Models/Post.php
Open in GitHubuse App\Scopes\PostedScope; use Illuminate\Database\Eloquent\Model; class Post extends Model { protected static function boot(): void { parent::boot(); static::addGlobalScope(new PostedScope); } {