Skip to content

Commit

Permalink
Add auto-incrementing column to both pivot tables
Browse files Browse the repository at this point in the history
Closes #382
  • Loading branch information
JosephSilber committed Jan 15, 2019
1 parent f143275 commit d2c2a8a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions migrations/create_bouncer_tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function up()
});

Schema::create(Models::table('assigned_roles'), function (Blueprint $table) {
$table->increments('id');
$table->integer('role_id')->unsigned()->index();
$table->integer('entity_id')->unsigned();
$table->string('entity_type');
Expand All @@ -60,6 +61,7 @@ public function up()
});

Schema::create(Models::table('permissions'), function (Blueprint $table) {
$table->increments('id');
$table->integer('ability_id')->unsigned()->index();
$table->integer('entity_id')->unsigned();
$table->string('entity_type');
Expand Down
9 changes: 6 additions & 3 deletions src/Conductors/Concerns/AssociatesAbilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,20 @@ protected function getAuthority()
*
* @param \Illuminate\Database\Eloquent\Model $authority
* @param array $abilityIds
* @param bool $forbidden
* @param bool $forbidden
* @return array
*/
protected function getAssociatedAbilityIds(Model $authority, array $abilityIds, $forbidden)
{
$relation = $authority->abilities();

$relation->whereIn('id', $abilityIds)->wherePivot('forbidden', '=', $forbidden);
$table = Models::table('abilities');

$relation->whereIn("{$table}.id", $abilityIds)
->wherePivot('forbidden', '=', $forbidden);

Models::scope()->applyToRelation($relation);

return $relation->get(['id'])->pluck('id')->all();
return $relation->get(["{$table}.id"])->pluck('id')->all();
}
}

0 comments on commit d2c2a8a

Please sign in to comment.