Hola ... no entiendo qué quiere hacer con el checkbox. Necesita de seleccionar varios checkboxes ? Qué es su problema con el checkbox ? Es la manera de recolectar el estado true o false ?
Mar 29, 2022
11
Level 1
Checkbox Laravel Livewire
Quiero implementar un checkbox en mi buscador, funciona de la siguiente manera al ingresar el numero de una factura me arroja la factura pero cada una tiene productos diferentes de la misma factura, entonces a veces es necesario seleccionar solo un registro de la misma factura y con el checkbox mi idea es seleccionar el registro o producto que requiero. Componente livewire class RecepcionFactura extends Component { protected $listeners = ['verModalFactura'];
use findFactura; public $recepcion; public $viewfacturaa = []; public $listRecepcion = []; public $modal = false;
public function render()
{
return view('livewire.recepcion-factura');
}
public function saveResults()
{
try {
DB::beginTransaction();
$fecha_oc = "";
$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();
}
}
public function verModalFactura()
{
$this->modal = true;
}
public function cerrarModalFactura()
{
$this->recepcion = null;
$this->listRecepcion = [];
$this->modal = false;
}
public function find()
{
$this->listRecepcion = $this->findFactura($this->recepcion);
}
}
Vista Livewire
@if ($modal) <div class="fixed z-10 inset-0 overflow-y-auto ease-out duration-400">
<div class="flex justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:p-0">
<div class="fixed inset-0 transition-opacity">
<div class="absolute inset-0 bg-gray-500 opacity-75"></div>
</div>
<span class="hidden sm:inline-block sm:align-middle sm:h-screen"></span>
<div class="inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-xl sm:w-full"
role="dialog" aria-modal="true" aria-labelledby="modal-headline">
<div class="bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4">
<label form="recepcion" class="block text-gray-700 text-sm font-bold mb-2">Facturas:</label>
<div class="inline-flex w-full">
<input name="recepcion" type="text"
class="form-control focus:outline-none focus:shadow-outline" wire:model.lazy="recepcion"
autocomplete="off">
<button wire:click="find()" class="btn btn-primary">Buscar</button>
</div>
@if (count($listRecepcion) > 0)
<button wire:click="saveResults()" class="mt-2 btn btn-success w-full">Guardar
Resultados</button>
@endif
<button wire:click="cerrarModalFactura()"
class="mt-2 btn btn-secondary w-full">Cancelar</button>
@if (count($listRecepcion) > 0)
<table class="w-full mt-4">
<thead class="bg-blue-900 text-white">
<tr>
<th class="border px-2 py-2 text-xs">Seleccion</th>
<th class="border px-2 py-2 text-xs">Factura</th>
<th class="border px-2 py-2 text-xs">Cliente</th>
<th class="border px-2 py-2 text-xs">Fecha</th>
<th class="border px-2 py-2 text-xs">Vendedor</th>
<th class="border px-2 py-2 text-xs">Producto</th>
<th class="border px-2 py-2 text-xs">Descripcion del producto</th>
</tr>
</thead>
<tbody>
@foreach ($listRecepcion as $r)
<tr>
<td class="border px-2 py-2 text-xs">
<input type="checkbox" value="{{ $r->PRODUCTO }}" ></td>
<td class="border px-2 py-2 text-xs">{{ $r->FACTURA }}</td>
<td class="border px-2 py-2 text-xs">{{ $r->DENOMINACION_SOCIAL }}</td>
<td class="border px-2 py-2 text-xs">{{ $r->FECHA }}</td>
<td class="border px-2 py-2 text-xs">{{ $r->NOMBRE_COMPLETO }}</td>
<td class="border px-2 py-2 text-xs">{{ $r->PRODUCTO }}</td>
<td class="border px-2 py-2 text-xs">{{ $r->DESCRIPCION_FACTURA }}</td>
</tr>
@endforeach
</tbody>
</table>
@else
<br>
@if (gettype($listRecepcion) == 'object')
<span class="text-red-600 text-bold">No se encontraron resultados.</span>
@endif
@endif
</div>
</div>
</div>
</div>
@endif
</div>
Please or to participate in this conversation.