I have two tables, User and Post. One User can have many posts and one post belongs to only one user.
In my User model I have a hasMany relation...
public function post(){
return $this->hasmany('post');
}
Run Code Online (Sandbox Code Playgroud)
And in my post model I have a belongsTo relation...
public function user(){
return $this->belongsTo('user');
}
Run Code Online (Sandbox Code Playgroud)
Now I want to join these two tables using Eloquent with() but want specific columns from the second table. I know I can use the Query …