title: Undefined variable: categories (View: resources\views\product\create.blade.php)
body: <p>hi m trying to get categories in products/create page but it says:  (View: \resources\views\product\create.blade.php) how to resolve it?</p>
  
  <p>controller:</p>
  
  <pre><code>public function create(Request $request)
  {
      $categories = Category::with('category')-&gt;distinct()-&gt;get();
  
      return view('product.create', compact('categories'));
  }
  </code></pre>
  
  <p>blade file:</p>
  
  <pre><code> &lt;select name="select"&gt;
       @foreach($categories as $category)
           &lt;option value="{{ $id }}"&gt;{{ $title }}&lt;/option&gt;
       @endforeach
   &lt;/select&gt;
  </code></pre>
  
  <p>category model:</p>
  
  <pre><code>public function products()
  {
      return $this-&gt;belongsToMany(Product::class,'category_product');
  }
  </code></pre>
  
  <p>product model:</p>
  
  <pre><code>public function categories()
  {
      return $this-&gt;belongsToMany(Category::class,'category_product');
  }
  </code></pre>
  
  <p>these are routes:</p>
  
  <pre><code>|        |           | GET|HEAD                   | password/reset/{token}     | password.reset          | App\Http\Controllers\Auth\ResetPasswordController@showResetForm        | web,guest    |
  |        | POST      | product                    | product.store           | App\Http\Controllers\ProductController@store                           | web          |
  |        | GET|HEAD  | product                    | product.index           | App\Http\Controllers\ProductController@index                           | web          |
  |        | GET|HEAD  | product/create             | product.create          | App\Http\Controllers\ProductController@create                          | web          |
  |        | DELETE    | product/{product}          | product.destroy         | App\Http\Controllers\ProductController@destroy                         | web          |
  |        | GET|HEAD  | product/{product}          | product.show            | App\Http\Controllers\ProductController@show                            | web          |
  |        | PUT|PATCH | product/{product}          | product.update          | App\Http\Controllers\ProductController@update                          | web          |
  |        | GET|HEAD  | product/{product}/edit     | product.edit            | App\Http\Controllers\ProductController@edit                            | web          |
  |        | POST      | register                   |                         | App\Http\Controllers\Auth\RegisterController@register                  | web,guest    |
  |        | GET|HEAD  | register                   | register                | App\Http\Controllers\Auth\RegisterController@showRegistrationForm      | web,guest    |
  </code></pre>