Answer the question
In order to leave comments, you need to log in
Can you please show a sample of correct migration for a pivot table in a many-to-many relationship (Laravel)?
Hello.
If anyone has a migration for a pivot table (Eloquent many-to-many) - please show the code. I didn't find it in the documentation.
Thank you.
Answer the question
In order to leave comments, you need to log in
public function up()
{
Schema::create('role_user', function (Blueprint $table) {
$table->increments('id');
$table->integer('role_id')->unsigned();
$table->foreign('role_id')->references('id')->on('roles');
$table->integer('user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users');
$table->timestamps();
});
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question