I am setting up a two database table, sale item and sale. When an admin make an inventory multiple sale item can added. After complete my sale inventory, i want to delete sale but i do not want to delete sale item table. My Sale Item migration table is:
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 migration table is:
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 Model :
public function sales(){
return $this->hasOne(Sale::class, 'id', 'sale_id');
}
Sale Model:
public function saleitems(){
return $this->hasMany(SalesItem::class, 'sale_id', 'id');
}
Now, How can i delete Sale table without delete sale item table?
from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2J5fr8j
via IFTTT
Aucun commentaire:
Enregistrer un commentaire