title: fetch datas from database based on selected data dropdown using laravel 8
body: <p>hai everyone i want to fetch data (affected device name, device intended use, class of device) from database based on my selected dropdown (mda registration num),i get the registration numb er from database but i don't how to fetch other related datas based on registration num.How i can gets datas.Here my controller n create.blade.php,pls help me</p>
  <p><a href="https://i.stack.imgur.com/JPQrv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JPQrv.png" alt="Interface" /></a></p>
  <p><strong>create.blade.php</strong></p>
  <pre><code>&lt;div class=&quot;form-group row&quot;&gt;
                              &lt;label for=&quot;inputMedName col-auto&quot;  class=&quot;col-lg-3 col-form-label &quot; for=&quot;mdaRegisNo1&quot;&gt;1.  MDA Device Registration No. &lt;span style=&quot;color:red;&quot;&gt;*&lt;/span&gt;&lt;/label&gt;
                              &lt;div class=&quot;col-6 col-lg-6&quot;&gt;
                                  &lt;select name=&quot;mdaRegisNo&quot; class=&quot;form-control &quot; id = &quot;mdaRegisNo1&quot; select data-size=&quot;5&quot; data-live-search=&quot;true&quot;&gt;
                                      &lt;option &gt; Select MDA Registration Number&lt;/option&gt;
                                  
                                      @foreach($devices as $key=&gt;$device)
                                      &lt;option value=&quot;{{$key}}&quot;&gt;{{$device-&gt;device_reg_no}}&lt;/option&gt;
                                      @endforeach
                                  &lt;/select&gt;  
  
                                  
                              &lt;/div&gt;
                              &lt;input type='button' value='Seleted option' id='but_read'&gt;
                              
                          &lt;/div&gt;
                          &lt;div class=&quot;form-group row&quot;&gt;
                              &lt;label class=&quot;col-lg-3 col-form-label &quot;&gt;2.  Affected Device Name &lt;span style=&quot;color:red;&quot;&gt;*&lt;/span&gt;&lt;/label&gt;
                              &lt;div class=&quot;col-9 col-lg-9&quot;&gt;
                                  &lt;input name=&quot;devName&quot; type=&quot;text&quot;  class=&quot;form-control&quot; &gt;
                              &lt;/div&gt;
                              
                              
                          &lt;/div&gt;
  
                          &lt;div class=&quot;form-group row&quot;&gt;
                              &lt;label class=&quot;col-lg-3 col-form-label &quot;&gt;3.  Device intended use &lt;span style=&quot;color:red;&quot;&gt;*&lt;/span&gt;&lt;/label&gt;
                              &lt;div class=&quot;col-9 col-lg-9&quot;&gt;
                                  &lt;input name=&quot;devUse&quot; type=&quot;text&quot; class=&quot;form-control&quot; &gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
  
                          &lt;div class=&quot;form-group row&quot;&gt;
                              &lt;label class=&quot;col-lg-3 col-form-label &quot;&gt;4.  Class of Device&lt;span style=&quot;color:red;&quot;&gt;*&lt;/span&gt;&lt;/label&gt;
                              &lt;div class=&quot;col-9 col-lg-9&quot;&gt;
                                  &lt;input name=&quot;devClass&quot; type=&quot;text&quot; class=&quot;form-control&quot; &gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
  </code></pre>
  <p><strong>RecallControlle.php</strong></p>
  <pre><code>public function create()
  {
      $recall = Recall::latest()-&gt;first();
      $ref_recall = 'MDA/Recall/P'.$this-&gt;getRefSuffix($recall);
  
      //$devices = DB::table('devices');
      $devices = Device::get();
  
      $post = Device::query();
  
      $device = DB::table('devices')-&gt;select('device_reg_no')-&gt;distinct()-&gt;get()-&gt;pluck('device_reg_no')-&gt;sort();
  
    
  
  
      //dd($devices);
      //return json_encode($devices);
  
      return view('recall.create',['devices'=&gt;$devices])-&gt;with([
          'ref_recall' =&gt; $ref_recall,
          'ref_mpr' =&gt; ''
      ]);
      
  }
  </code></pre>