I am using Laravel 5.7 and i have following tables
category
id | category_name
post_categories
id | category_id | post_id | some other fields
posts
id | post_title
i have belongs to many relationship in category Model
public function post(){
return $this->belongsToMany(Post::class,'post_categories','category_id','post_id')
->withPivot('col2', 'col3','col4');
}
$response=Category::with('post')->get();
This will return has expected but now i dont need category detail in my response i mean is it possible to declare relationship in pivot model since i know category_id and i can avoid category detail in my response
my aim is to retrieve all post by category id