protected function getBandsByGenre($genre, $excludeIds = []) { $query = Band::where('assigned_genre', $genre['name']); if (!empty($excludeIds)) { $query->whereNotIn('id', $excludeIds); } $bands = $query->get(); if (count($bands) < config('services.echonest.threshold')) { event(app(NeedMoreBands::class)->setGenre($genre)); } return $bands; }
public function updateArtists($genres) { foreach ($genres as $genre) { if (empty($genre)) { continue; } $artists = $this->uploadBandsByGenre($genre->name); foreach ($artists as $artist) { $mainGenre = $this->getMainGenre($artist['data']['genres']); if (empty($mainGenre)) { continue; } $band = Band::updateOrCreate(['name' => $artist['name']], ['name' => $artist['name'], 'data' => json_encode($artist['data']), 'assigned_genre' => $mainGenre])->toArray(); foreach ($artist['data']['images'] as $image) { Image::updateOrCreate(['link' => $image], ['link' => $image, 'band_id' => $band['id'], 'status' => 'new']); } } } }