getRepository(Business::class)->findBy(['owner'=>$user]); $response = []; foreach ($buss as $bus){ $temp = []; $temp['id'] = $bus->getId(); $temp['name'] = $bus->getName(); $temp['owner'] = $bus->getOwner()->getFullName(); $temp['legal_name'] = $bus->getLegalName(); $response[] = $temp; } return $this->json($response); } #[Route('/api/business/list/count', name: 'api_bussiness_list_count')] public function api_bussiness_list_count(#[CurrentUser] ?User $user,EntityManagerInterface $entityManager): Response { $buss = $entityManager->getRepository(Business::class)->findBy(['owner'=>$user]); $response = ['count'=>count($buss)]; return $this->json($response); } }