koel/app/Services/PlaylistService.php
Allen Taylor aae444a9b4
fix: made rules optional (#1370)
Co-authored-by: Allen Taylor <allen.taylor@check24.de>
Co-authored-by: Phan An <me@phanan.net>
2021-10-25 21:17:25 +02:00

24 lines
524 B
PHP

<?php
namespace App\Services;
use App\Models\Playlist;
use App\Models\User;
class PlaylistService
{
public function createPlaylist(string $name, User $user, array $songs, ?array $ruleGroups = null): Playlist
{
/** @var Playlist $playlist */
$playlist = $user->playlists()->create([
'name' => $name,
'rules' => $ruleGroups,
]);
if (!$playlist->is_smart && $songs) {
$playlist->songs()->sync($songs);
}
return $playlist;
}
}