Symofny - query sum : I am writing a query  which will return amount of total spent money for that user. Total spent = sum of all transaction amounts, where type = spend. I have set my type field in a base to 'spend'.. 

It returns 

> Invalid parameter: token type is not defined in the query.

My code.

    public function getTotal(User $user, $type)
    {
        $query = $this->getSpendingRepository()
            ->createQueryBuilder('p')
            ->select("count(p.amount) as total_amount")
            ->where('p.type = :spend')
            ->andWhere('p.user = :user')
            ->setParameters(['user' => $user,
                             'type' => $type])
            ->getQuery()
            ->getOneOrNullResult();

        return $query;
    }