简体   繁体   English

Laravel顺序通过深厚的关系

[英]Laravel orderBy with deep relationship

Can someone help me to solve my issue with ordering. 有人可以帮我解决订购问题。

I have 4 tables: 我有4张桌子:

posts 
[id]

post_values 
[id, post_id, value_id, value_text]

post_category_field_values 
[id]

post_category_field_value_translations 
[id, value_id, 'locale', 'name']

I need to get all posts ordered by translated value name. 我需要按转换后的值名称来排序所有帖子。

maybe Jarek's answer will help you 也许Jarek的答案会帮助您

    $products = Shop\Product::join('shop_products_options as po', 'po.product_id', '=', 'products.id')
   ->orderBy('po.pinned', 'desc')
   ->select('products.*')       // just to avoid fetching anything from joined table
   ->with('options')         // if you need options data anyway
   ->paginate(5);

Laravel Eloquent sort by relation table column Laravel Eloquent按关系表列排序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM