当我尝试在 laravel 中插入对象时出现此错误,这是我在控制器类中的函数:
public function insertDelete(Producto $item) { $date = date('Y-m-d'); $venta=new venta(); $venta->fechaVenta=$date; $venta->user_id=$item->user_id; $venta->producto_id=$item->id; $venta->envio_id=$item->envio_id; $venta->save(); Producto::where('id',$item->id)->delete(); return view('pruebas');}
我的路线:
@foreach ($ticket as $item)<div class="d-flex my-2 justify-content-center"> <a href="{{ route('insertDelete' , $item) }}" class="btn btn-success btn-label waves-effect right waves-light rounded-pill"><i class="ri-check-double-line label-icon align-middle rounded-pill fs-16 ms-2"></i> Finalizar Compra</a> </div>@endforeach
我的 web.php
Route::get('pruebas/', [\App\Http\Controllers\VentaController::class, 'insertDelete'] )->name('insertDelete');
P粉4821083102024-03-22 17:57:26
在您的路由中,您没有指定路由模型绑定的参数。您正在期待 $item
,在这种情况下您需要这样的东西:
Route::get('pruebas/{$item}', [\App\Http\Controllers\VentaController::class, 'insertDelete'] )->name('insertDelete');