Reputation: 21
Javascript: {data:'category_name',name:'sale.sale_detail.product.category.category_name'} is it possible to access multi level relationship?
sale table has a sub table"sale_detail" and sale_detail contains product_id and also product table has id of category table
Upvotes: 1
Views: 1448
Reputation: 1189
Let me give you an example from my code. You can use join
as mentioned by @Japheth Suarez:
$category = Category::findOrFail($slug);
$reviews = DB::table('reviews')
->join('users', 'reviews.user_id', '=', 'users.id')
->select('reviews.*', DB::raw('CONCAT(users.first_name, " ", users.last_name) AS full_name'))
->where('category_id', '=', $category->id);
Let me say to you that I have tried Eager Loading
with DataTables but never worked very good in terms of performance. So the best solution for me was to use join
instead of using it this way $posts = Post::with('user')->select('posts.*');
.
Hope that this helps. Happy coding!
Upvotes: 3