Я настраиваю таблицу из двух баз данных: пункт продажи и продажа.Когда администратор делает инвентарь, можно добавить несколько предметов продажи.После завершения продажи я хочу удалить продажу, но не хочу удалять таблицу товаров.Таблица миграции My Sale Item:
public function up()
{
Schema::create('sales_items', function (Blueprint $table) {
$table->increments('id');
$table->string('product_name');
$table->string('product_price');
$table->string('product_quantity');
$table->string('product_discount');
$table->string('total_price');
$table->integer('status');
$table->integer('sale_id')->unsigned();
$table->foreign('sale_id')->references('id')->on('sales')- >onDelete('cascade');
$table->timestamps();
});
}
Таблица миграции Sale:
public function up()
{
Schema::create('sales', function (Blueprint $table) {
$table->increments('id');
$table->string('sale_status');
$table->string('total_price');
$table->string('due');
$table->timestamps();
});
}
Модель SaleItem:
public function sales(){
return $this->hasOne(Sale::class, 'id', 'sale_id');
}
Модель продажи:
public function saleitems(){
return $this->hasMany(SalesItem::class, 'sale_id', 'id');
}
Теперь, как я могу удалить таблицу продаж без удаления таблицы элементов продажи?