laravel Route::resource 无法删除

laravel Route::resource not working for delete

Laravel Route::resource('countries', 'CountriesController'); 现在正在为 DELETE

工作

仅作为(单独)工作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>

不工作,我卡在 url: http://192.168.1.7:8000/countries/6/delete

saying '404|not found'

您不需要在 URL 中附加 /delete

试试这个:

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

如@nakov 所述,您还可以删除隐藏的输入字段。 blade 指令 @method('DELETE') 足以完成这项工作。

希望对您有所帮助!