I am trying this Query in Laravel 5.2
User::with(['posts'])
->withCount('post_images')
->orderBy('post_images_count', 'desc')
->take(8)
->get();
After that I got this error Call to undefined method Illuminate\Database\Query\Builder::post_images()
I did not understand what mistake is here.
Here users table
has relation with posts Table
and Posts table has relation with post_images table
public function posts()
{
return $this->hasMany(Post::class);
}
public function postimages()
{
return $this->hasManyThrough(PostImage::class, Post::class);
}
Please guide How can I fix this.