Laravel 5如何在循环中进行循环

How can i make loop like this in laravel?

I have category and posts table ,
on posts table there is field for category id.

And some categories has no post , so i dont want to show empty categories on my view..

Sorry for my english . I hope you understand me

Loop:Category {

$categoryname

Loop:PostsBelongsToCategory {

$postTitle

}
}

I want to print it to page like this :

Category 1 :

Category 1 Post A ,

Category 1 Post B ,

Category 1 Post C ,

Category 2 :

Category 2 Post A ,

Category 2 Post B ,

Category 2 Post C ,

Setup your relations between the categories and posts table.

$categories = App\Categroy::with('posts')->get();

foreach($categories as $category) {
    echo $category->name;
    foreach($category->posts as $post) {
        echo $category->name.' '.$post->title.',';
    }
}