koel/app/Http/Controllers/API/SongController.php

32 lines
974 B
PHP
Raw Normal View History

2015-12-13 04:42:28 +00:00
<?php
namespace App\Http\Controllers\API;
2016-03-05 09:01:12 +00:00
use App\Http\Requests\API\SongUpdateRequest;
2017-04-24 06:38:41 +00:00
use App\Models\Song;
2018-08-29 06:30:39 +00:00
use App\Repositories\AlbumRepository;
use App\Repositories\ArtistRepository;
2015-12-13 04:42:28 +00:00
class SongController extends Controller
{
2021-06-05 10:47:56 +00:00
private ArtistRepository $artistRepository;
private AlbumRepository $albumRepository;
2018-08-18 13:19:40 +00:00
2021-06-05 10:47:56 +00:00
public function __construct(ArtistRepository $artistRepository, AlbumRepository $albumRepository)
{
2018-08-29 06:30:39 +00:00
$this->artistRepository = $artistRepository;
$this->albumRepository = $albumRepository;
2018-08-18 13:19:40 +00:00
}
2016-03-05 09:01:12 +00:00
public function update(SongUpdateRequest $request)
{
2018-08-29 06:30:39 +00:00
$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,
]);
2016-03-05 09:01:12 +00:00
}
2015-12-13 04:42:28 +00:00
}