已关闭,此问题需要details or clarity。目前不接受答复。
**想改善这个问题吗?**通过editing this post添加详细信息并澄清问题。
22小时前关闭
Improve this question
我试图删除一个特定的数据与相应的id,但它重定向我到显示页面,虽然路由是指导它销毁。
我的索引刀片
<td><form class="action"><button type="submit" formaction="{{route('products.show',$product->id)}}">Show</button></form></td>
<td><form class="action"><button type="submit" formaction="{{route('products.edit',$product->id)}}">Edit</button></form></td>
<td><form class="delete" action="{{ route('products.destroy',$product->id) }}">
@csrf
@method('DELETE')
<button>Delete</button>
</form></td>
我的毁灭控制器
public function destroy(Product $product)
{
$product->delete();
return redirect()->route('products.index')->with('success','Data deleted successfully!!!');
}
我的控制器用于显示
public function show(Product $product)
{
return view('products.show',compact('product'));
}
我的索引控制器
{
$products = Product::latest()->paginate(5);
return view('products.index',compact('products'));
}````
Route
````Route::resource('/products',ProductController::class);````
I tried using <a> link tag also but it does the same and also the data gets deleted perfectly fine when I delete it from database manually.
2条答案
按热度按时间bvjxkvbb1#
您的删除按钮窗体没有按钮
type="submit"
也没有method="post"
尝试下面的代码。我希望这能解决你的问题。
2jcobegt2#