/**
  * Sync an organisation with new repositories.
  *
  * @param \App\Models\Organisation\Organisation $organisation
  * @param \Illuminate\Support\Collection        $repositories
  *
  * @return void
  */
 public function sync(Organisation $organisation, Collection $repositories)
 {
     $existing = $organisation->repositories;
     $repositories = $this->map($repositories);
     $repositories = $this->create($repositories, $existing);
     $organisation->repositories()->saveMany($repositories);
 }
Exemplo n.º 2
0
 /**
  * Sync a user with new organisations.
  *
  * @param \App\Models\User\User          $user
  * @param \Illuminate\Support\Collection $organisations
  *
  * @return void
  */
 public function sync(User $user, Collection $organisations)
 {
     $existing = Organisation::query()->whereIn('id', $organisations->lists('id'))->get();
     $user->organisations()->detach();
     $organisations = $this->map($organisations);
     $organisations = $this->create($organisations, $existing);
     $user->organisations()->attach($organisations->lists('id')->toArray());
 }