Add ability to edit the playlist name and visibility #5
This commit is contained in:
@@ -95,6 +95,34 @@ class PlaylistController extends Controller
|
||||
return to_route('profile.playlists');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update user playlist.
|
||||
*/
|
||||
public function updatePlaylist(Request $request, $playlist_id): RedirectResponse
|
||||
{
|
||||
if (! is_numeric($playlist_id)) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$validated = $request->validate([
|
||||
'name' => 'required|max:30',
|
||||
'is_private' => 'required|boolean',
|
||||
]);
|
||||
|
||||
$user = $request->user();
|
||||
|
||||
$playlist = Playlist::where('user_id', $user->id)
|
||||
->where('id', $playlist_id)
|
||||
->firstOrFail();
|
||||
|
||||
$playlist->update([
|
||||
'name' => $request->input('name'),
|
||||
'is_private' => $request->input('is_private'),
|
||||
]);
|
||||
|
||||
return back()->with('status', 'playlist-updated');
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete user playlist.
|
||||
*/
|
||||
|
||||
@@ -26,6 +26,10 @@ class PlaylistOverview extends Component
|
||||
|
||||
public Collection $playlistEpisodes;
|
||||
|
||||
public bool $editingName = false;
|
||||
|
||||
public string $editingPlaylistName = '';
|
||||
|
||||
public function boot(PlaylistService $playlistService)
|
||||
{
|
||||
$this->playlistService = $playlistService;
|
||||
@@ -112,6 +116,53 @@ class PlaylistOverview extends Component
|
||||
$this->refreshEpisodes();
|
||||
}
|
||||
|
||||
public function editName()
|
||||
{
|
||||
if (! Auth::check() || Auth::user()->id !== $this->playlist->user->id) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->editingPlaylistName = $this->playlist->name;
|
||||
$this->editingName = true;
|
||||
}
|
||||
|
||||
public function cancelEditName()
|
||||
{
|
||||
$this->editingName = false;
|
||||
$this->editingPlaylistName = '';
|
||||
}
|
||||
|
||||
public function updateName()
|
||||
{
|
||||
if (! Auth::check() || Auth::user()->id !== $this->playlist->user->id) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->validate([
|
||||
'editingPlaylistName' => 'required|max:30',
|
||||
]);
|
||||
|
||||
$this->playlist->update([
|
||||
'name' => $this->editingPlaylistName,
|
||||
]);
|
||||
|
||||
$this->editingName = false;
|
||||
$this->editingPlaylistName = '';
|
||||
}
|
||||
|
||||
public function toggleVisibility()
|
||||
{
|
||||
if (! Auth::check() || Auth::user()->id !== $this->playlist->user->id) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->playlist->update([
|
||||
'is_private' => ! $this->playlist->is_private,
|
||||
]);
|
||||
|
||||
$this->playlist->refresh();
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.playlist-overview', [
|
||||
|
||||
@@ -7,6 +7,26 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Playlist extends Model
|
||||
{
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'name',
|
||||
'is_private',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'is_private' => 'boolean',
|
||||
];
|
||||
|
||||
/**
|
||||
* Belongs To A User.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user