remove softdeletes to allow for range deletion when all products are deleted
This commit is contained in:
parent
578dcd2f5c
commit
572f7fb4df
2 changed files with 48 additions and 1 deletions
|
|
@ -12,7 +12,8 @@ use Gloudemans\Shoppingcart\CanBeBought;
|
|||
class Product extends Model implements Buyable
|
||||
{
|
||||
use HasFactory;
|
||||
use SoftDeletes;
|
||||
//no more softdeletes
|
||||
//use SoftDeletes;
|
||||
use CanBeBought;
|
||||
|
||||
/**
|
||||
|
|
@ -47,6 +48,7 @@ class Product extends Model implements Buyable
|
|||
$model->discountedPriceHt = $model->getDiscountedPriceHtAttribute();
|
||||
$model->discountedPriceTtc = $model->getDiscountedPriceTtcAttribute();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
use App\Models\Product;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class RemoveSofdeleteFromProductsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
* ajout une cascade vers foodProduct
|
||||
* lance un delete des produits sofdelete puis
|
||||
* supprime la colonne de softdelete
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('food_products', function (Blueprint $table) {
|
||||
$table->dropForeign('food_products_product_id_foreign');
|
||||
$table->foreign('product_id')
|
||||
->references('id')->on('products')
|
||||
->onDelete('cascade');
|
||||
});
|
||||
|
||||
Product::onlyTrashed()->forceDelete();
|
||||
|
||||
Schema::table('products', function (Blueprint $table) {
|
||||
$table->dropSoftDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('products', function (Blueprint $table) {
|
||||
//
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue