Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

koel/koel

16858 stars
2 code files
View koel/koel on GitHub

app/Repositories/ArtistRepository.php

Open in GitHub
use App\Models\Song;
 
class ArtistRepository extends AbstractRepository
{
public function getNonEmptyArtistIds(): array
{
return Song::select('artist_id')
->groupBy('artist_id')
->get()
->pluck('artist_id')
->toArray();
}
}

app/Http/Controllers/API/SongController.php

Open in GitHub
use App\Http\Requests\API\SongUpdateRequest;
use App\Models\Song;
use App\Repositories\AlbumRepository;
use App\Repositories\ArtistRepository;
 
class SongController extends Controller
{
private ArtistRepository $artistRepository;
private AlbumRepository $albumRepository;
 
public function __construct(ArtistRepository $artistRepository, AlbumRepository $albumRepository)
{
$this->artistRepository = $artistRepository;
$this->albumRepository = $albumRepository;
}
 
public function update(SongUpdateRequest $request)
{
$updatedSongs = Song::updateInfo($request->songs, $request->data);
 
return response()->json([
'artists' => $this->artistRepository->getByIds($updatedSongs->pluck('artist_id')->all()),
'albums' => $this->albumRepository->getByIds($updatedSongs->pluck('album_id')->all()),
'songs' => $updatedSongs,
]);
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.