Borjan Mukaetov
Borjan Mukaetov

Reputation: 27

laravel Route::resource not working for delete

Laravel Route::resource('countries', 'CountriesController'); now working for DELETE

Working only as (separately)Route::delete('/countries/{country}/delete', 'CountriesController@destroy');

<div class="row">
    <div class="col-12">
        <h1>Details for {{ $country->countryName }}</h1>
        <p><a href="/countries/{{ $country->id }}/edit">Edit</a></p>

        <form action="/countries/{{ $country->id }}/delete" method="post">
            <input name="_method" type="hidden" value="DELETE">
            @method('DELETE')
            @csrf
            <button type="submit" class="btn btn-danger">Delete1</button>

        </form>
    </div>
</div>

not working, I'm stuck at url: http://192.168.1.7:8000/countries/6/delete

saying '404|not found'

Upvotes: 0

Views: 149

Answers (1)

Zeshan
Zeshan

Reputation: 2657

You don't need to append /delete in the URL.

Try this:

<form action="/countries/{{ $country->id }}" method="post">
    @method('DELETE')
    @csrf
    <button type="submit" class="btn btn-danger">Delete1</button>
</form>

As mentioned by @nakov, you can also remove the hidden input field. The blade directive @method('DELETE') is sufficient to do the job.

Hope it helps!

Upvotes: 6

Related Questions