I try to delete some of my post with slug but it's not found. My route:
Route::resource('/dashboard/berita', DashboardController::class)->parameters([
'berita' => 'post:slug'
])->middleware('auth');
My Controller:
public function destroy(Post $post) {
$post->delete();
return redirect('/dashboard/berita')->with('success', 'Berita sudah dihapus!');
}
My blade:
<form action="{/dashboard/berita/{{ $post->slug }}}" method="post" >
@method('delete')
@csrf
<button > </button>
</form>
CodePudding user response:
Your formatting is wrong, it should be
action="/dashboard/berita/{{ $post->slug }}"
Or better still, use a named route.
<form action="{{ route('post.destroy', $post )}}" >
CodePudding user response:
The problem is with this section of your code: action="{/dashboard/berita/{{ $post->slug }}}"
you need to change it as below:
<form action="{{ url('/dashboard/berita/' . $post->slug) }}" method="post" >
</form>