Init
This commit is contained in:
30
app/Services/PlaylistService.php
Normal file
30
app/Services/PlaylistService.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Playlist;
|
||||
use App\Models\PlaylistEpisode;
|
||||
|
||||
class PlaylistService
|
||||
{
|
||||
public function reorderPositions(Playlist $playlist): void
|
||||
{
|
||||
$episodes = PlaylistEpisode::where('playlist_id', $playlist->id)
|
||||
->orderBy('position')
|
||||
->get();
|
||||
|
||||
foreach ($episodes as $index => $episode) {
|
||||
$episode->position = $index + 1;
|
||||
$episode->save();
|
||||
}
|
||||
}
|
||||
|
||||
public function swapPositions(PlaylistEpisode $a, PlaylistEpisode $b): void
|
||||
{
|
||||
$temp = $a->position;
|
||||
$a->position = $b->position;
|
||||
$b->position = $temp;
|
||||
$a->save();
|
||||
$b->save();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user