Example of Local scopes in spatie/spatie.be

File app/Models/Ad.php (link to Github)
use Illuminate\Database\Eloquent\Model;

class Ad extends Model
{
    public function scopeActive(Builder $query): void
    {
        $query->where('active', true);
    }
}
File app/Jobs/RandomizeAdsOnGitHubRepositoriesJob.php (link to Github)
use App\Models\Ad;
use App\Models\Repository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Spatie\ArtisanDispatchable\Jobs\ArtisanDispatchable;

class RandomizeAdsOnGitHubRepositoriesJob implements ShouldQueue, ArtisanDispatchable
{
    public function handle()
    {
        $ads = Ad::active()->get();

        Repository::adShouldBeRandomized()->each(function (Repository $repository) use ($ads) {
            $repository->ad()->associate($ads->random());

            $repository->save();
        });
    }
}

Additional resources on local scopes: