php – Loop through categories and display posts title under each dropdown

I want to loop through categories and display posts title under each dropdown of category and on clicking post name from dropdown, display post content in tab pane in wordpress. Please suggest code solution.

‘types’,
‘orderby’ => ‘name’,
‘order’ => ‘ASC’
);

$cats = get_categories($args);

$c = 1;
foreach($cats as $cat) {
?>

              <li class="nav-item dropdown">
                <a class="nav-link dropdown-toggle <?=($c == 1) ? 'active' : ''?>" href="#<?php echo $cat->name; ?>" role="button" data-toggle="tab" aria-haspopup="true" aria-expanded="false"><?php echo $cat->name; ?></a>
                <div class="dropdown-menu">

                  <?php 

                  $cat_slug = $category->slug;

                  $the_query = new WP_Query(array(
                  'post_type' => 'project',
                  'category_name' => $cat_slug
                    )); 

                  while($the_query->have_posts()){
                    $the_query->the_post();
                   ?>
                  

                  <a class="dropdown-item" href="#<?php the_ID(); ?>" data-toggle="tab"><?php the_title(); ?></a>

                <?php } wp_reset_postdata(); ?>
                 
                </div>
              </li>

            <?php $c++; } wp_reset_postdata(); ?>