/**
  * Get the IDs of the associated abilities.
  *
  * @param  \Illuminate\Database\Eloquent\Model  $authority
  * @param  array  $abilityIds
  * @param  bool $forbidden
  * @return array
  */
 protected function getAssociatedAbilityIds(Model $authority, array $abilityIds, $forbidden)
 {
     return $authority->abilities()->whereIn('id', $abilityIds)->wherePivot('forbidden', '=', $forbidden)->get(['id'])->pluck('id')->all();
 }
Example #2
0
 /**
  * Give abilities to the given model.
  *
  * @param  array  $ids
  * @param  \Illuminate\Database\Eloquent\Model  $model
  * @return void
  */
 protected function giveAbilities(array $ids, Model $model)
 {
     $existing = $model->abilities()->whereIn('id', $ids)->lists('id')->all();
     $ids = array_diff($ids, $existing);
     $model->abilities()->attach($ids);
 }
 /**
  * Detach the given IDs from the model, with the given pivot constraints.
  *
  * @param  \Illuminate\Database\Eloquent\Model  $model
  * @param  array  $ids
  * @param  array  $constraints
  * @return void
  */
 protected function detachAbilitiesWithPivotConstraints(Model $model, $ids, $constraints)
 {
     $relation = $model->abilities();
     $query = $relation->newPivotStatement();
     $query->where($relation->getForeignKey(), $model->getKey())->whereIn($relation->getOtherKey(), $ids)->where($constraints)->delete();
 }