Laravel类别,子类别和邮政

I have a 1 category and subcategory table table name: categories

enter image description here

another table is posts posts table

enter image description here

when click on google app script all post regarding category and sub category of google app script will show enter image description here

enter image description here

my controller code is and name of controller is bloglistController

$posts = post::where('category_id', $id)->paginate(7);

but this code shows only category id post I want post of both category and sub category

For category model

public function post()
{
    return $this->hasMany(Post::class, 'parent_id', 'category_id');
}

In your controller

$category = Category::where('parent_id',1)->first();
$post = $category->post;