Save query select
Hello, could someone help me with my functions, I want to save only one record of my queries and not save them all in my database, that is, I need to select only 1 and not save all of them, I am using Laravel livewire and Traits, I attach code. This is my save function in my component.
public function saveResults()
{
try {
DB::beginTransaction();
$listRecepcion = $this->findFactura($this->recepcion);
foreach ($listRecepcion as $item) {
// $item->fecha_oc = $fecha_oc;
$this->createdNewRecepcion($item);
}
DB::commit();
$this->emit('render');
$this->cerrarModalRecepcion();
} catch (\Exception $e) {
DB::rollBack();
}
}
This is my function where the search is done, it is located in my component
public function find()
{
$this->listRecepcion = $this->findFactura($this->recepcion);
}
This is my Trait where a query is made and a new record is created in my table This is my search function where I query a table in sql
public function findFactura($recepcion)
{
return viewfacturaa::select(
'FACTURA',
'FECHA',
'DENOMINACION_SOCIAL',
'NOMBRE_COMPLETO',
'CANTIDAD',
'PRODUCTO',
'DESCRIPCION_FACTURA',
'MONEDA',
'TC',
'PRECIO_UNIDAD',
'SUBTOTAL',
'TOTAL_IVA'
)
->where('FACTURA', '=', $recepcion)
->get();
}
And in this function I save the sql data in a table in mysql
private function createdNewRecepcion($data)
{
factura::create([
'factura' => trim($data->FACTURA),
'fecha_vencimiento' => trim($data->FECHA),
'cliente' => trim($data->DENOMINACION_SOCIAL),
'vendedor' => trim($data->NOMBRE_COMPLETO),
'cantidad' => $data->CANTIDAD,
'producto' => trim($data->PRODUCTO),
'descripcion' => trim($data->DESCRIPCION_FACTURA),
'moneda' => trim($data->MONEDA),
'tc' => $data->TC,
'precio_unidad' => $data->PRECIO_UNIDAD,
'subtotal' => $data->SUBTOTAL,
// 'total' => $data->TOTAL,
'total_iva' => $data->TOTAL_IVA,
]);
}
What I want is to save only 1 record of my array and not all
Please or to participate in this conversation.