R
R
Roman2019-02-09 03:41:28
Laravel
Roman, 2019-02-09 03:41:28

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

2 answer(s)
R
Roman, 2019-02-09
@procode

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();
      });
    }

J
JhaoDa, 2019-02-09
@JhaoDa

At a minimum, this is a table with two fields - two identifiers, one entity and the second. What to show?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question