I have two tables, User and Post. One User can have many posts and one post belongs to only one user>
If you want to get specific columns using with() in laravel eloquent then you can use code as below which is originally answered by @Adam in his answer here in response of this same question :
Post::with('user:id,username')->get();
So i have used it in my code but it was giving me error of 1052: Column 'id' in field list is ambiguous, so if you guys are also facing same problem
Then for solving it you have to specify table name before the id column in with() method as below code:
Post::with('user:user.id,username')->get();