You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have the following problem:
when adding a new provider on form, the provider is added as part of the menu options but is not displayed as the default option, why is this happening and how can I fix it?
Steps to reproduce
I have this code on my view form:
x-slot:before
</x-slot:before>
I have this code on my AdminComponent:
#[On('proveedorGuardado')]
public function seleccionarProveedor($id)
{
Log::info("Entra a Seleccionar Proveedor");
Log::info($id);
// dd($id);
// Agregar el nuevo proveedor a la lista de opciones
$nuevoProveedor = Proveedor::findOrFail($id);
$this->proveedores[] = [
'value' => $nuevoProveedor['id'],
'label' => $nuevoProveedor['nombre'],
];
$this->model->id_proveedor = $id;
}
public function handleSearch($searchTerm)
{
// dd($searchTerm);
$proveedores = collect();
/*
$id = $request->get('id');
if ($id) {
// Buscar el proveedor por ID para incluirlo como opción preseleccionada
$selectedOption = Proveedor::where('id', $id)
->where('id_empresa', Auth::user()->empresa()->id)
->where('activo', 1)
->where('es_cliente', 0)
->first();
if ($selectedOption) {
$options->push([
'value' => $selectedOption->id, // Clave para custom-select
'label' => $selectedOption->nombre, // Valor para custom-select
]);
}
}
*/
// Buscar proveedores solo si el término tiene al menos 3 caracteres
if (strlen($searchTerm) >= 3) {
$searchResults = Proveedor::where('nombre', 'like', '%' . $searchTerm . '%')
->where('id_empresa', Auth::user()->empresa()->id)
->where('activo', 1)
->where('es_cliente', 0)
->get(['id', 'nombre'])
->map(fn($option) => [
'value' => $option->id, // Clave para custom-select
'label' => $option->nombre, // Valor para custom-select
]);
// Combinar los resultados de búsqueda con el proveedor preseleccionado
$proveedores = $proveedores->merge($searchResults);
}
$this->proveedores = $proveedores;
}
And this is the code of my component for create a provider:
public function save()
{
$this->validate();
try {
$this->proveedor->es_cliente = 0;
$this->proveedor->save();
$this->close(); // Cierra el modal
$this->alert('success', 'Proveedor registrado correctamente.');
// Emitir el evento con el ID del proveedor guardado
$this->dispatch('proveedorGuardado', $this->proveedor->id);
session()->flash('success', 'Proveedor registrado correctamente.');
} catch (\Exception $e) {
Log::info($e);
$this->dispatch('modal.close');
session()->flash('success', 'Proveedor no se registró correctamente.');
}
}
Relevant log output
No response
The text was updated successfully, but these errors were encountered:
Laravel Form Components Version
v8.x
Laravel Version
v11
Alpine Version
No response
Bug description
I have the following problem:
when adding a new provider on form, the provider is added as part of the menu options but is not displayed as the default option, why is this happening and how can I fix it?
Steps to reproduce
I have this code on my view form:
x-slot:before
</x-slot:before>
I have this code on my AdminComponent:
#[On('proveedorGuardado')]
public function seleccionarProveedor($id)
{
Log::info("Entra a Seleccionar Proveedor");
Log::info($id);
// dd($id);
// Agregar el nuevo proveedor a la lista de opciones
$nuevoProveedor = Proveedor::findOrFail($id);
$this->proveedores[] = [
'value' => $nuevoProveedor['id'],
'label' => $nuevoProveedor['nombre'],
];
And this is the code of my component for create a provider:
public function save()
{
$this->validate();
try {
$this->proveedor->es_cliente = 0;
$this->proveedor->save();
$this->close(); // Cierra el modal
$this->alert('success', 'Proveedor registrado correctamente.');
// Emitir el evento con el ID del proveedor guardado
$this->dispatch('proveedorGuardado', $this->proveedor->id);
session()->flash('success', 'Proveedor registrado correctamente.');
} catch (\Exception $e) {
Log::info($e);
$this->dispatch('modal.close');
session()->flash('success', 'Proveedor no se registró correctamente.');
}
}
Relevant log output
No response
The text was updated successfully, but these errors were encountered: