-
app/Models/Ad.php
Open in GitHubuse Illuminate\Database\Eloquent\Model; class Ad extends Model { public function scopeActive(Builder $query): void { $query->where('active', true); } }
-
app/Jobs/RandomizeAdsOnGitHubRepositoriesJob.php
Open in GitHubuse 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(); }); } }