culeaalex's avatar

Delete route not found

Hi.

I have made a gallery images upload and now want to make the delete method, but submitting the delete form redirects me to a 404 page.

web.php

Route::middleware(['auth'])->group(function () {
  //[.......]//
    Route::delete('series/{series}/gallery_image/{$image}','Series\SeriesController@deleteGalleryImage')->name('series.gallery_image.destroy');
});

route:list

DELETE    | series/{series}/gallery_image/{$image} | series.gallery_image.destroy  | App\Http\Controllers\Series\SeriesController@deleteGalleryImage        | web,auth

blade template

<form method="post" action="{{ route('series.gallery_image.destroy',[$series->id,$photo->id]) }}" onsubmit="return confirm('Really delete?')">
                                                            @method('DELETE')
                                                            @csrf
                                                            <button type="submit" class="btn btn-danger"><i class="feather icon-trash-2"></i></button>
                                                        </form>

Form submits to http://localhost/series/2/gallery_image/1 which shows me a 404 page

What am I doing wrong?

0 likes
3 replies
siangboon's avatar

try add this after the form opening tag

...
@csrf
@method('DELETE')
...
guybrush_threepwood's avatar

Hi @culeaalex I can't find anything wrong with your code. Could you paste the code from SeriesController@deleteGalleryImage?

Maybe you're redirecting to a page that doesn't exist?

Snapey's avatar
Snapey
Best Answer
Level 122

you have a $ in your route

Route::delete('series/{series}/gallery_image/{$image}'
                                              ^
2 likes

Please or to participate in this conversation.