找不到可选参数返回404时的Laravel 5.8删除路由

时间:2019-05-06 09:41:32

标签: laravel-5.8

提交删除表单时,未设置可选参数时得到404。

仅当我从控制器中删除可选参数时,它才会提交。

作品:

<form action="{{ route('images.destroyall', [ 'post' => 1 ])}}" method="POST">
    @csrf
    @method('DELETE')
    <button type="submit" class="btn btn-danger btn-lg btn-block"><i class="fa fa-remove"></i> remove all</button>
</form>

不工作:

<form action="{{ route('images.destroyall', [ 'post' => NULL ])}}" method="POST">
    @csrf
    @method('DELETE')
    <button type="submit" class="btn btn-danger btn-lg btn-block"><i class="fa fa-remove"></i> remove all</button>
</form>

OR

<form action="{{ route('images.destroyall')}}" method="POST">
    @csrf
    @method('DELETE')
    <button type="submit" class="btn btn-danger btn-lg btn-block"><i class="fa fa-remove"></i> remove all</button>
</form>

routes.php:

Route::delete('/images/deleteall/{post?}','ImageController@destroyAll')->name('images.destroyall')->middleware('auth');

ImageController.php:

class ImageController extends Controller
{
    public function destroyAll($post_id = null)
    {
        dd($post_id);
    }
}

当我碰巧获得路线时,一切正常。但这是不好的做法...希望您能帮助我...这是laravel 5.8中的错误吗?我错过了什么吗?

0 个答案:

没有答案