i have this situation in my db:
projects = id | title | slug
products = id | project_id | category_id
likes = id | project_id | user_id
I would like get all products with a specific "category_id", with "status" pubblished and order by project's likes (paginate for 21 products).
$products = Product::where('category_id', $category->id)->where('status','published')->with('project')->get()->sortBy(function($product)
{
return $product->project->like->count();
})->paginate(21);
Without "->paginate(21)" work well, so i get this error:
BadMethodCallException in Macroable.php line 74: Method paginate does not exist.