[英]Laravel Delete Route 404 Not Found
為什么我試圖從願望清單中刪除產品,我收到 404 錯誤?
在我的家中。php,我有這個:
Route::prefix('profile')->middleware(['auth'])->group(function () {
Route::get('', [ProfileController::class, 'index']);
Route::get('/twofactor', [ProfileController::class, 'manageTwoFactor']);
Route::post('/twofactor', [ProfileController::class, 'activeTwoFactor']);
Route::get('/twofactor/phone',[ProfileController::class,'getPhoneNumberVerify'])->name('profile.2fa.phone');
Route::post('/twofactor/phone',[ProfileController::class,'postPhoneNumberVerify']);
Route::get('/orders',[OrderController::class,'index']);
Route::get('/orders/{order}',[OrderController::class,'show'])->name('order.details');
Route::get('/orders/{order}/payment',[OrderController::class,'payment'])->name('profile.order.payment');
Route::resource('/wishlist',WishlistController::class)>except(['show','create','update','edit']);}); //wishlist routes
在我的 controller 我有這個:
public function destroy(Wishlist $wishlist)
{
$wishlist->delete();
return back();
}
<div class="flex-grow-one">
<form action="{{route('wishlist.destroy',$wish->product_id)}}"
method="post" id="delete-wish-{{$wish->product_id}}">
@csrf
@method('delete')
</form>
<a href="javascript:" onclick="document.getElementById('delete-wish-
{{$wish->product_id}}').submit();" class="remove-favorite">
<i class="fa fa-trash-alt"></i></a>
</div>
你的願望清單應該類似於 /profile/wishlist/{wishlist} 所以在這種情況下刪除重定向回這個願望清單但你已經刪除了它,所以它會顯示 404。你已經顯示可能在那里使用一些索引或退回到另一條路線。
路線('profile.wishlist.index');
然后它將顯示索引,您可以將其配置為顯示所有願望清單,或者您可以按照自己的方式進行操作。
因為最后你 go 回到了前一頁並且前一頁被刪除了元素和。 不再可用
public function destroy(Wishlist $wishlist)
{
$wishlist->delete();
return back();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.