jeudi 15 novembre 2018

writing migration tables for many to many relations in laravel 5.6

i dont know how write migration tables for many to many relations . here are my codes

Schema::create('staff', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->string('email')->unique();
        $table->string('password');
        $table->string('firstname');
        $table->string('lastname');
        $table->char('link', 100)->nullable();
        $table->string('country')->nullable();
        $table->string('city')->nullable();
        $table->string('occupation')->nullable();
        $table->string('zipcode')->nullable();
        $table->string('photo')->nullable();
        $table->rememberToken();
        $table->timestamps(); });

Schema::create('roles', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->integer('staff_id')->unsigned();
        $table->foreign('staff_id')->references('id')->on('staff');
        $table->timestamps();
    });
Schema::create('role_staff', function (Blueprint $table) {
        $table->increments('id');
        $table->integer('role_id')->unsigned();
        $table->integer('staff_id')->unsigned();;
        $table->foreign('staff_id')->references('id')->on('staff');
        $table->foreign('role_id')->references('id')->on('roles');
        $table->timestamps();
    });

I am not sure I did right in terms of foreign keys?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire