Answer the question
In order to leave comments, you need to log in
How to use composite keys in Laravel relationships?
I use composite keys in related tables -
Schema::create('order_details', function (Blueprint $table) {
$table->integer('order_id');
$table->integer('product_id');
$table->decimal('price')->unsigned();
$table->primary(['order_id', 'product_id']);
});
Schema::create('order_details_services', function (Blueprint $table) {
$table->integer('order_id');
$table->integer('product_id');
$table->integer('service_id');
$table->decimal('price')->unsigned();
$table->primary(['order_id', 'product_id', 'service_id']);
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question