2022-09-15 09:07:25 +00:00
|
|
|
<?php
|
|
|
|
|
2023-06-05 21:46:41 +00:00
|
|
|
namespace App\Http\Requests\API;
|
2022-09-15 09:07:25 +00:00
|
|
|
|
2024-01-06 11:31:50 +00:00
|
|
|
use App\Facades\License;
|
|
|
|
use App\Models\Song;
|
|
|
|
|
2022-09-15 09:07:25 +00:00
|
|
|
/** @property-read array<string> $songs */
|
|
|
|
class DeleteSongsRequest extends Request
|
|
|
|
{
|
|
|
|
/** @return array<mixed> */
|
|
|
|
public function rules(): array
|
|
|
|
{
|
|
|
|
return [
|
2023-10-10 15:29:30 +00:00
|
|
|
'songs' => 'required|array|exists:songs,id',
|
2022-09-15 09:07:25 +00:00
|
|
|
];
|
|
|
|
}
|
2024-01-06 11:31:50 +00:00
|
|
|
|
|
|
|
public function authorize(): bool
|
|
|
|
{
|
|
|
|
if (License::isCommunity()) {
|
|
|
|
return $this->user()->is_admin;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Song::query()
|
|
|
|
->whereIn('id', $this->songs)
|
|
|
|
->get()
|
|
|
|
->every(fn (Song $song): bool => $song->owner_id === $this->user()->id);
|
|
|
|
}
|
2022-09-15 09:07:25 +00:00
|
|
|
}
|