SQLSTATE: Integrity constraint violation: 1048 Column 'user_id' cannot be null
P粉576184933
P粉576184933 2024-03-21 22:18:07
0
1
385

I get this error when I try to insert an object in laravel, this is my function in the controller class:

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:

@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

Route::get('pruebas/', [\App\Http\Controllers\VentaController::class, 'insertDelete'] )->name('insertDelete');

P粉576184933
P粉576184933

reply all(1)
P粉482108310

In your route, you do not specify the parameters of the route model binding. You are expecting $item , in which case you want something like this:

Route::get('pruebas/{$item}', [\App\Http\Controllers\VentaController::class, 'insertDelete'] )->name('insertDelete');
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template