mirror of
https://github.com/koel/koel
synced 2024-11-28 06:50:27 +00:00
aae444a9b4
Co-authored-by: Allen Taylor <allen.taylor@check24.de> Co-authored-by: Phan An <me@phanan.net>
24 lines
524 B
PHP
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;
|
|
}
|
|
}
|