Flag of Ukraine
SymfonyCasts stands united with the people of Ukraine
Next Chapter

Challenge #1 of 1


Q: 

On the "Category" page, I've added a search box that will allow my users to search for products that are in that category. Here's the query I built for this in ProductRepository:

public function searchCategory(Category $category, string $search): array
{
    return $this->createQueryBuilder('product')
        ->andWhere('product.category = :category')
        ->andWhere('product.name LIKE :term')
        ->orWhere('product.description LIKE :term')
        ->setParameter('category', $category)
        ->setParameter('term', '%'.$search.'%')
        ->getQuery()
        ->getResult();
}

Is this correct?

userVoice