英文:
Laravel (hasManyThrough eloquent relation) - WhereHas with OrderBy working on localhost, not working on server
问题
Laravel(hasManyThrough eloquent relation)- 在本地环境正常工作,但在服务器上不正常工作。在本地环境中,它可以正常排序,但在生产服务器上无法正确排序。
在本地环境中使用的是MARIADB,在生产服务器上使用的是MYSQL。
public function index(Product $product)
{
$products = Product::with(['subcategory', 'subcategory.category'])->whereHas('subcategory', function ($query) {
$query->whereHas('category', function ($query) {
$query->orderBy('category_id', 'asc');
});
})->get();
return view('products.index', compact('products'));
}
英文:
Laravel (hasManyThrough eloquent relation) - WhereHas with OrderBy working on localhost, not working on server. On localhost it working, it sorting (ordering) well, but on live server dont ordering well.
On localhost is MARIADB on live server is MYSQL.
public function index(Product $product)
{
$products = Product::with(['subcategory', 'subcategory.category'])->whereHas('subcategory', function ($query) {
$query->whereHas('category', function ($query) {
$query->orderBy('category_id', 'asc');
}); })->get();
return view('products.index', compact('products'));
}
答案1
得分: 1
更改您的关系如下:
public function brands()
{
return $this->hasManyThrough('App\Brand', 'App\Product', 'category_id', 'id', 'brand_id');
}
英文:
change your relationship as below:
public function brands()
{
return $this->hasManyThrough('App\Brand', 'App\Product' 'category_id','id','brand_id');
}
答案2
得分: 0
尝试这样做:
$products = Product::with(['subcategory', 'subcategory.category'])
->has('subcategory.category')->orderBy('category_id', 'asc')->get();
return view('products.index', compact('products'));
英文:
Try this
$products = Product::with(['subcategory', 'subcategory.category'])
->has('subcategory.category')->orderBy('category_id', 'asc')->get();
return view('products.index', compact('products'));
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论