So, I’m making a streaming website in laravel php and I am trying to make a watchlist function. The button to put data in the database works. Where it begins to become a headache is with the remove button, when I click on the remove button it just refreshes my page and my database stays intact. I have a second problem: my videos-cards don’t display on the watch list page (this is just a minor problem, the biggest problem is the database removal).
public function remove(Request $request) {
$user = Auth::user();
$videoId = $request->input('video');
DB::table('watch_later')->where('user_id', Auth::id())->where('video_id', $videoId)->delete();
return redirect()->back()->with('success', 'video removed from Watch Later');
}
this is my remove function in controller.
@if($watchLaterVideos->isEmpty())
<p>No videos</p>
@else
@foreach($watchLaterVideos as $video)
<a href="{{ route('videos.show', $video) }}">
<img src="{{URL('./images/' . $video->img) }}" alt="{{ $video->name }}">
<h5>{{$video->name}}</h5>
</a>
<form action="{{ route('watch-later.remove') }}" method="POST">
@csrf
@method('DELETE')
<input type="hidden" name="video_id" value="{{ $video->id }}">
<button type="submit">Remove from Watch Later</button>
</form>
@endforeach
@endif
this is my blade content
Route::post('/watch-later/add', [AppHttpControllersWatchLaterController::class, 'add'])->name('watch-later.add');
Route::delete('/watch-later/remove', [AppHttpControllersWatchLaterController::class, 'remove'])->name('watch-later.remove');
and these are my routes
Michael Stoikos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.