2022-08-10 14:56:01 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
|
|
|
use App\Models\PlaylistFolder;
|
|
|
|
use App\Models\User;
|
|
|
|
|
|
|
|
class PlaylistFolderService
|
|
|
|
{
|
|
|
|
public function createFolder(User $user, string $name): PlaylistFolder
|
|
|
|
{
|
|
|
|
return $user->playlist_folders()->create(['name' => $name]);
|
|
|
|
}
|
|
|
|
|
2022-09-08 05:06:49 +00:00
|
|
|
public function renameFolder(PlaylistFolder $folder, string $name): PlaylistFolder
|
2022-08-10 14:56:01 +00:00
|
|
|
{
|
|
|
|
$folder->update(['name' => $name]);
|
|
|
|
|
|
|
|
return $folder;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addPlaylistsToFolder(PlaylistFolder $folder, array $playlistIds): void
|
|
|
|
{
|
2024-03-27 09:53:05 +00:00
|
|
|
$folder->playlists()->attach($playlistIds);
|
2022-08-10 14:56:01 +00:00
|
|
|
}
|
|
|
|
|
2024-03-27 09:53:05 +00:00
|
|
|
public function movePlaylistsToRootLevel(PlaylistFolder $folder, array $playlistIds): void
|
2022-08-10 14:56:01 +00:00
|
|
|
{
|
2024-03-27 09:53:05 +00:00
|
|
|
$folder->playlists()->detach($playlistIds);
|
2022-08-10 14:56:01 +00:00
|
|
|
}
|
|
|
|
}
|