Update CreateOjalPresilla.php
This commit is contained in:
@@ -11,7 +11,7 @@ class CreateOjalPresilla extends CreateRecord
|
|||||||
|
|
||||||
protected static ?string $title = 'Crear';
|
protected static ?string $title = 'Crear';
|
||||||
|
|
||||||
protected function mutateFormDataBeforeCreate(array $data): array
|
protected function handleRecordCreation(array $data): \Illuminate\Database\Eloquent\Model
|
||||||
{
|
{
|
||||||
$distribuciones = $data['distribuciones'] ?? [];
|
$distribuciones = $data['distribuciones'] ?? [];
|
||||||
$tipo = $data['tipo'] ?? 'accesorio';
|
$tipo = $data['tipo'] ?? 'accesorio';
|
||||||
@@ -28,8 +28,9 @@ class CreateOjalPresilla extends CreateRecord
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Crear un registro por cada proveedor
|
// Crear un registro por cada proveedor
|
||||||
|
$primerRegistro = null;
|
||||||
foreach ($distribuciones as $distribucion) {
|
foreach ($distribuciones as $distribucion) {
|
||||||
\App\Models\Ojal::create([
|
$registro = \App\Models\Ojal::create([
|
||||||
'proveedor_id' => $distribucion['proveedor_id'],
|
'proveedor_id' => $distribucion['proveedor_id'],
|
||||||
'orden_produccion_id' => $ordenProduccionId,
|
'orden_produccion_id' => $ordenProduccionId,
|
||||||
'tipo' => $tipo,
|
'tipo' => $tipo,
|
||||||
@@ -37,20 +38,14 @@ class CreateOjalPresilla extends CreateRecord
|
|||||||
'cantidad_enviada' => $distribucion['cantidad'],
|
'cantidad_enviada' => $distribucion['cantidad'],
|
||||||
'terminada' => $terminada,
|
'terminada' => $terminada,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if (!$primerRegistro) {
|
||||||
|
$primerRegistro = $registro;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Redirigir al listado
|
// Retornar el primer registro para que Filament no falle
|
||||||
$this->redirect(OjalPresillaResource::getUrl('index'));
|
return $primerRegistro;
|
||||||
|
|
||||||
// Retornar vacío para evitar que Filament intente crear el registro automáticamente
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function afterCreate(): void
|
|
||||||
{
|
|
||||||
// Ya se crearon los registros en mutateFormDataBeforeCreate
|
|
||||||
// Redirigir al index
|
|
||||||
$this->redirect(OjalPresillaResource::getUrl('index'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getRedirectUrl(): string
|
protected function getRedirectUrl(): string
|
||||||
|
|||||||
Reference in New Issue
Block a user