Laravel命令与他们有着深厚的关系

时间:2017-12-25 09:47:43

标签: php mysql laravel eloquent

有人可以帮我解决我的订购问题。

我有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']

我需要按翻译的值名称排序所有帖子。

1 个答案:

答案 0 :(得分:0)

也许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