1

Can someone help me to solve my issue with ordering.

I have 4 tables:

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.

lieroes
  • 674
  • 2
  • 12
  • 29
  • you have not stored post_id in post_category_feild_value_transaltions? – kunal Dec 25 '17 at 10:00
  • No, I have categories with fields. When I create a post I should define values for each field from category in "post_values" table. – lieroes Dec 25 '17 at 10:02
  • Now I'm trying to make a sort and order feature. Later I want to add a filter feature. – lieroes Dec 25 '17 at 10:05
  • So I want to order this relation: $posts = Post::with('value.value.translation')->orderBy('value.value.translation.name', 'ASC')->get(); – lieroes Dec 25 '17 at 10:08

1 Answers1

0

maybe Jarek's answer will help you

    $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

Etibar
  • 578
  • 6
  • 22