Soft Delete
This commit is contained in:
@@ -67,16 +67,17 @@ class ImportarExcelLimpio extends Command
|
||||
$precioLimpio = (float) str_replace(['$', ' ', ','], '', $precioRaw);
|
||||
|
||||
// 5. Creación o Actualización
|
||||
Product::updateOrCreate(
|
||||
Product::withTrashed()->updateOrCreate(
|
||||
['name' => $nombreFinal],
|
||||
[
|
||||
'description' => $descripcionRaw,
|
||||
'type' => $tipoFinal,
|
||||
'cost' => $costoLimpio,
|
||||
'price' => $precioLimpio,
|
||||
'suppliers_id' => $proveedorId, // Asociación dinámica
|
||||
'suppliers_id' => $proveedorId,
|
||||
'stock_quantity' => 20,
|
||||
'min_stock_alert' => 5,
|
||||
'deleted_at' => null,
|
||||
]
|
||||
);
|
||||
|
||||
@@ -87,9 +88,6 @@ class ImportarExcelLimpio extends Command
|
||||
$this->info("¡Éxito! Se procesaron {$contador} productos con sus respectivos proveedores.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Crea los proveedores básicos si no existen para evitar errores de integridad.
|
||||
*/
|
||||
private function asegurarProveedores()
|
||||
{
|
||||
$proveedores = [
|
||||
@@ -99,9 +97,13 @@ class ImportarExcelLimpio extends Command
|
||||
];
|
||||
|
||||
foreach ($proveedores as $id => $name) {
|
||||
Supplier::firstOrCreate(
|
||||
Supplier::withTrashed()->firstOrCreate(
|
||||
['id' => $id],
|
||||
['name' => $name, 'phone' => '0000000000']
|
||||
[
|
||||
'name' => $name,
|
||||
'phone' => '0000000000',
|
||||
'deleted_at' => null
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,11 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
class Client extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use SoftDeletes;
|
||||
protected $guarded = [];
|
||||
protected $fillable = ['name', 'phone', 'email', 'address'];
|
||||
|
||||
|
||||
@@ -4,10 +4,12 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Product extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use SoftDeletes;
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'description',
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
class Supplier extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use SoftDeletes;
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'phone',
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('products', function (Blueprint $table) {
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('products', function (Blueprint $table) {
|
||||
$table->dropSoftDeletes();
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('clients', function (Blueprint $table) {
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('clients', function (Blueprint $table) {
|
||||
$table->dropSoftDeletes();
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('suppliers', function (Blueprint $table) {
|
||||
$table->softDeletes(); // Agrega 'deleted_at' a proveedores
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('suppliers', function (Blueprint $table) {
|
||||
$table->dropSoftDeletes();
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user