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

28 lines
832 B
PHP
Raw Normal View History

2024-01-10 21:37:24 +00:00
<?php
namespace App\Http\Controllers\API;
use App\Http\Controllers\Controller;
use App\Http\Requests\API\InteractWithMultipleSongsRequest;
use App\Models\Song;
use App\Models\User;
use App\Services\InteractionService;
use Illuminate\Contracts\Auth\Authenticatable;
2024-01-10 23:25:22 +00:00
use Illuminate\Support\Collection;
2024-01-10 21:37:24 +00:00
class LikeMultipleSongsController extends Controller
{
/** @param User $user */
public function __invoke(
InteractWithMultipleSongsRequest $request,
InteractionService $interactionService,
Authenticatable $user
) {
/** @var Collection<array-key, Song> $songs */
2024-01-10 21:37:24 +00:00
$songs = Song::query()->findMany($request->songs);
$songs->each(fn (Song $song) => $this->authorize('access', $song));
return response()->json($interactionService->likeMany($songs, $user));
}
}