title: Undefined variable $attributes (View: C:\xampp\htdocs\rainbow\resources\views\dashboard\options\edit.blade.php) --- relation between two models
body: <p>There are two modals attributes  &amp;  its options</p>
  <p>the problem now in options edit blade</p>
  <p>This part of code  was work correctly in create.blade</p>
  <p>**but in edit.blade ** show this error.</p>
  <p>Then I try to add this variable to the controller in several ways but still the same error appears</p>
  <p>you can find my codes down, please help me</p>
  <p><strong>edit.blade</strong></p>
  <pre><code>&lt;div class=&quot;form-body&quot;&gt;
      &lt;h4 class=&quot;form-section&quot;&gt;
          &lt;i class=&quot;ft-home&quot;&gt;&lt;/i&gt; Option name
      &lt;/h4&gt;
      &lt;div class=&quot;row&quot;&gt;
          &lt;div class=&quot;col-md-6&quot;&gt;
              &lt;div class=&quot;form-group&quot;&gt;
                  &lt;label for=&quot;projectinput1&quot;&gt; Choose a feature
                  &lt;/label&gt;
                  &lt;select name=&quot;attribute_id&quot; class=&quot;select2 form-control&quot; &gt;
                      &lt;optgroup label=&quot;Choose a feature &quot;&gt;
                          @if($attributes &amp;&amp; $attributes -&gt; count() &gt; 0)
                              @foreach($attributes as $attribute)
                                  &lt;option
                                      value=&quot;{{$attributes -&gt; id }}&quot;&gt;{{$attributes -&gt; name}}&lt;/option&gt;
                              @endforeach
                          @endif
                      &lt;/optgroup&gt;
                  &lt;/select&gt;
                  @error('attribute_id')
                  &lt;span class=&quot;text-danger&quot;&gt; {{$message}}&lt;/span&gt;
                  @enderror
              &lt;/div&gt;
          &lt;/div&gt;
  </code></pre>
  <p><strong>attribute model</strong></p>
  <pre><code>public function options() {
      return $this-&gt;hasMany(Option::class, 'attribute_id');
  }
  </code></pre>
  <p><strong>option model</strong></p>
  <pre><code>public function attribute() {
      return $this-&gt;belongsTo(Attribute::class, 'attribute_id');
  }
  </code></pre>
  <p><strong>controller</strong></p>
  <pre><code>public function edit($id)
  {
      //get specific options and its translations
  
      $option = Option::orderBy('id', 'DESC')-&gt;find($id);
      if (!$option)
          return redirect()-&gt;route('admin.options')-&gt;with(['error' =&gt; 'this option is not available']);
  
      return view('dashboard.options.edit', compact('option'));
  }
  
  public function update($id, OptionsRequest $request)
  {
      try {
          //validation
  
          //update DB
  
          $option = Option::find($id);
          if (!$option)
              return redirect()-&gt;route('admin.options')-&gt;with(['error' =&gt; 'this option is unavailable']);
  
          if (!$request-&gt;has('is_active'))
              $request-&gt;request-&gt;add(['is_active' =&gt; 0]);
          else
              $request-&gt;request-&gt;add(['is_active' =&gt; 1]);
  
          $option-&gt;update($request-&gt;except('_token', 'id'));
  
          //save translations
          $option-&gt;name = $request-&gt;name;
          $option-&gt;save();
  
          DB::commit();
  
          return redirect()-&gt;route('admin.options')-&gt;with(['success' =&gt; 'success']);
      } catch (\Exception $ex) {
          return redirect()-&gt;route('admin.options')-&gt;with(['error' =&gt; 'fail, try again later']);
      }
  }
  </code></pre>