title: Laravel findOrFail method for multiple table
body: <p>There is two tables categories and category types. I'm trying get category by slug and category type with id. How can I check whether these two tables and data exists ?</p>
  
  <p>My code: </p>
  
  <pre><code>public function typeIndex($slug, $typeId)
      {
          $category = Category::findBySlug($slug)-&gt;with('types')-&gt;whereHas('types',function(Builder $builder) use ($typeId){
              return $builder-&gt;where('id',$typeId);
          });
  
          return view('frontend.category.index', compact('category'));
      }
  </code></pre>