SQLSTATE: Integrity constraint violation: 1048 Column 'user_id' cannot be null
I get this error when I try to insert an object in laravel, this is my function in the controller class:
1 2 3 4 5 6 7 8 9 10 11 12 | 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' );}
|
My route:
1 2 3 | @ 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
|
My web.php
1 | Route::get( 'pruebas/' , [\App\Http\Controllers\VentaController:: class , 'insertDelete' ] )->name( 'insertDelete' );
|