【发布时间】:2022-01-21 13:56:43
【问题描述】:
为什么我要尝试从愿望清单中删除产品,但出现 404 错误?
在我的 home.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
在我的控制器中,我有这个:
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>
【问题讨论】:
-
尝试运行
php artisan route:list并查看销毁路线 -
可能是
$wishlist的Wishlist模型未找到,所以它抛出 404 错误 -
我已经这样做了,并且有销毁路线