Is there any advantages of having an id column in a pivot table (many to many relationship) in Laravel (i'm using version 5.1)?
With an id
$table->increments('id');
$table->integer('appointment_id')->unsigned();
$table->foreign('appointment_id')->references('id')->on('appointments')->onDelete('cascade');
$table->integer('client_id')->unsigned();
$table->foreign('client_id')->references('id')->on('clients')->onDelete('cascade');
$table->timestamps();
Without an id
$table->integer('appointment_id')->unsigned();
$table->foreign('appointment_id')->references('id')->on('appointments')->onDelete('cascade');
$table->integer('client_id')->unsigned();
$table->foreign('client_id')->references('id')->on('clients')->onDelete('cascade');
$table->timestamps();
In general, the answer is no, provided that Laravel's Eloquent models are managing the relationship.
If, however, you need to access the tables from outside of Eloquent models (say, from another application or in the distant future when you rewrite your application to use the next big framework), an ID will come in handy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With