vendredi 25 novembre 2016

how to access pivot table column

I have bican roles plugin and I need to access over pivot table. This is in my controller code

   $users = User::where('role_id','=',2)->get();

migration roles

   Schema::create('roles', function (Blueprint $table) {
        $table->increments('id')->unsigned();
        $table->string('name');
        $table->string('slug')->unique();
        $table->string('description')->nullable();
        $table->integer('level')->default(1);
        $table->timestamps();
    });

migration user

   Schema::create('users', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name')->unique();
        $table->string('email')->unique();
        $table->rememberToken();
        $table->timestamps();
    });

pivot migration

   Schema::create('role_user', function (Blueprint $table) {
        $table->increments('id')->unsigned();
        $table->integer('role_id')->unsigned()->index();
        $table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade');
        $table->integer('user_id')->unsigned()->index();
        $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
        $table->timestamps();
    });



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire