mirror of
https://github.com/koel/koel
synced 2024-11-10 06:34:14 +00:00
Allow smart playlist creation
This commit is contained in:
parent
e7ad687f8a
commit
d58b791c37
4 changed files with 18 additions and 5 deletions
|
@ -40,8 +40,17 @@ class PlaylistController extends Controller
|
|||
*/
|
||||
public function store(PlaylistStoreRequest $request)
|
||||
{
|
||||
$playlist = $request->user()->playlists()->create($request->only('name'));
|
||||
$playlist->songs()->sync((array) $request->songs);
|
||||
/** @var Playlist $playlist */
|
||||
$playlist = $request->user()->playlists()->create([
|
||||
'name' => $request->name,
|
||||
'rules' => $request->rules,
|
||||
]);
|
||||
|
||||
$songs = (array) $request->songs;
|
||||
|
||||
if ($songs) {
|
||||
$playlist->songs()->sync($songs);
|
||||
}
|
||||
|
||||
$playlist->songs = $playlist->songs->pluck('id');
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@ namespace App\Http\Requests\API;
|
|||
|
||||
/**
|
||||
* @property string[] $songs
|
||||
* @property string $name
|
||||
* @property array $rules
|
||||
*/
|
||||
class PlaylistStoreRequest extends Request
|
||||
{
|
||||
|
|
|
@ -27,6 +27,7 @@ class Playlist extends Model
|
|||
'user_id' => 'int',
|
||||
'rules' => 'array',
|
||||
];
|
||||
protected $appends = ['is_smart'];
|
||||
|
||||
public function songs(): BelongsToMany
|
||||
{
|
||||
|
|
|
@ -26,6 +26,7 @@ class PlaylistTest extends TestCase
|
|||
$this->postAsUser('api/playlist', [
|
||||
'name' => 'Foo Bar',
|
||||
'songs' => $songs->pluck('id')->toArray(),
|
||||
'rules' => [],
|
||||
], $user);
|
||||
|
||||
$this->seeInDatabase('playlists', [
|
||||
|
|
Loading…
Reference in a new issue