Answer the question
In order to leave comments, you need to log in
What is the correct way to write with with aggregate functions?
There are 2 tables: products and reviews .
Products store information about a product, and reviews store reviews about it.
And there is a relationship:
public function rev()
{
return $this -> hasMany( Review::class )-> whereVerify(1);
}
public function rev_count()
{
return $this -> hasMany( Review::class )-> whereVerify(1) -> count();
}
$product = Product::whereId(1)->first();
echo $product -> rev_count();
$product = Product::whereId(1) -> with('rev_count')->first() -> toJson();
[Symfony\Component\Debug\Exception\FatalThrowableError]
Call to a member function addEagerConstraints() on integer
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question