title: How can create a Nova filter to filter a resource by its relation?
body: <p>I have a question resource that has many categories (many to many relation). I would like to create a filter the question resource for different categories.</p>
  
  <pre><code>&lt;?php
  
  namespace App\Nova\Filters;
  
  use Illuminate\Http\Request;
  use Laravel\Nova\Filters\Filter;
  
  class CategoryType extends Filter
  {
      /**
       * Apply the filter to the given query.
       *
       * @param  \Illuminate\Http\Request  $request
       * @param  \Illuminate\Database\Eloquent\Builder  $query
       * @param  mixed  $value
       * @return \Illuminate\Database\Eloquent\Builder
       */
      public function apply(Request $request, $query, $value)
      {
          return $query-&gt;categories()-&gt;where('id', $value);
      }
  
      /**
       * Get the filter's available options.
       *
       * @param  \Illuminate\Http\Request  $request
       * @return array
       */
      public function options(Request $request)
      {
              $categories = \App\Category::all();
              return $categories-&gt;pluck('id', 'name')-&gt;all();
      }
  }
  </code></pre>