31 lines
687 B
PHP
31 lines
687 B
PHP
<?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();
|
|
}
|
|
}
|