im trying to create a query that counts the total products from a user, but my code isnt working, i leave above my code:
Tables: Galleries:
- id;
- title
Products
- id;
- gallery_id;
- title;
- price
Models: Gallery
public function products(){
return $this->hasMany(Product::class);
}
My query:
$totalProducts = Gallery::where('user_id', $userId)->products()->count();
Error:
Non-static method App\Gallery::products() should not be called statically, assuming $this from incompatible context