There are two table. Under a category there is a product name. So, this product name must be unique.? Like cat1 has pro1,pro2 cat2 has pro1,pro3
Table 1 (Migration):
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCategoryTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('catefory', function (Blueprint $table) {
$table->increments('id');
$table->string('name')->unique();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('category');
}
}
Tbl2 (Migration )
public function up()
{
Schema::create('products', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->foreign('category_id')->references('id')->on('category');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('products');
}
For each category there should be a unique product name. How to define this in laravel migration so that each category there should be a unique products name.?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire