I'm trying to load last 5 comments with related posts selecting only id and title from post.
In first case I decided get all columns from posts:
Comment::with(['post'])->take(5)->orderBy('id', 'desc')->get();
And it's working fine.
But when I try get only two columns ("id, title") then nothing from posts is loaded.
Comment::with(['post:id,title'])->take($number)->orderBy('id', 'desc')->get();
I did a test and when I removed "orderBy('id', 'desc')" then was fine again.
Comment::with(['post:id,title'])->take($number)->get();
So must be some problem with "orderBy" option.
Is it any way to fix it? It's mean get only selected columns from "posts" table and order results from the last one?
Thank you.
id
you want to order.id
of post orid
of comment. – u_mulder