I have three models
Posts
Users
UserImages
In Posts I have
public function user() {
return $this->belongsTo(new User)->with('avatar');
}
In User I have
public function avatar() {
return $this->hasOne(UserImage::class)->where('type', 1); //type 1 is avatar;
}
I call from Posts controller and I have screenshot below:
$posts = $this->model::select('*')->with('user')->get();
It returns too much information. I want to select something like thÃ
Is possible with hasOne and belongsTo ?