defaultRelations); } private ?ContactRepository $RepositoryContact = null; private function initContactRepository(): ?ContactRepository { if (! $this->RepositoryContact) { $this->RepositoryContact = new ContactRepository; } return $this->RepositoryContact; } public function addContact($supplierId, $contactIds = []): bool { $repo = $this->initContactRepository(); foreach ((array) $contactIds as $contactId) { $repo->setContactRelation($contactId, $supplierId, $this->Model); } return true; } public function removeContact($supplierId, $contactIds = []): bool { $repo = $this->initContactRepository(); foreach ((array) $contactIds as $contactId) { $repo->unsetContactRelation($contactId, $supplierId, $this->Model); } return true; } public function syncContact($supplierId, $contactIds = []): bool { // $model=new Supplier(); // $model=new $this->Model(); $item = $this->Model::find($supplierId); return $item->syncContactRelations((array) $contactIds); } public function addProductGroup($supplierId, $productGroupIds = []): bool { $item = $this->Model::find($supplierId); $item->productGroup()->syncWithoutDetaching($productGroupIds); return true; } public function removeProductGroup($supplierId, $productGroupIds = []): bool { $item = $this->Model::find($supplierId); $item->productGroup()->detach($productGroupIds); return true; } public function syncProductGroup($supplierId, $productGroupIds = []): bool { $item = $this->Model::find($supplierId); $item->productGroup()->sync($productGroupIds); return true; } public function syncService($supplierId, $productGroupIds = []): bool { $item = $this->Model::find($supplierId); $item->service()->sync($productGroupIds); return true; } public function syncProfitCenter($supplierId, $profitCenterIds = []): bool { $item = $this->Model::find($supplierId); $item->profitCenter()->sync($profitCenterIds); return true; } public function syncUsers($supplierId, $userIds = []): bool { \App\Models\User::where('supplier_id', $supplierId)->whereNotIn('id', $userIds)->update(['supplier_id' => null]); if (count($userIds) > 0) { \App\Models\User::whereIn('id', $userIds)->update(['supplier_id' => $supplierId]); } return true; } /** * Get's a record by it's ID * * @param int * @return collection */ /* public function getWithRelations($id){ if($data=$this->getQueryWithRelations()->where('id',$id)->get()->first()){ if(count($data->attachment)>0){ $data['logoImgUrl']=$data->attachment[0]['publicUrl']; } } return $data; }*/ }