koel/app/Http/Controllers/API/UploadAlbumCoverController.php
2024-07-06 17:44:46 +02:00

24 lines
668 B
PHP

<?php
namespace App\Http\Controllers\API;
use App\Http\Controllers\Controller;
use App\Http\Requests\API\UploadAlbumCoverRequest;
use App\Models\Album;
use App\Services\MediaMetadataService;
class UploadAlbumCoverController extends Controller
{
public function __invoke(UploadAlbumCoverRequest $request, Album $album, MediaMetadataService $mediaMetadataService)
{
$this->authorize('update', $album);
$mediaMetadataService->writeAlbumCover(
$album,
$request->getFileContentAsBinaryString(),
$request->getFileExtension()
);
return response()->json(['cover_url' => $album->cover]);
}
}