skip to Main Content

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" class="d-inline">
    @method('delete')
    @csrf
    <button class="badge bg-danger border-0"> </button>
</form>

2

Answers


  1. 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 )}}" >
    
    
    Login or Signup to reply.
  2. 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" class="d-inline">
    
    </form>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search