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