提交删除表单时,未设置可选参数时得到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中的错误吗?我错过了什么吗?