title: How to combine two different tables in different database using SQL in laravel
body: <p>Expect:</p>
  <ol>
  <li><code>select robotid, number from tool where is_active = 1</code></li>
  <li><code>select * from robot_team where id = robotid( robotid from tool)</code></li>
  <li><code>foreach id(from robot_team), number(from tool) , status_za(from robot_team), status_zb(from robot_team), status_zm(from robot_team), status_qs(from robot_team)</code></li>
  </ol>
  <p>Result:</p>
  <ol>
  <li>cannot show success through postman</li>
  </ol>
  <p>Code:</p>
  <pre><code>public function robotStatus()
      {
          $arr=[];
                  
          $robotlist = DB::table('robot_team AS u')
                  -&gt;Join(DB::connection('sql')-&gt;table('tool AS m'), 'u.id', '=', 'm.robotid')
                  -&gt;select('u.*', 'u.id AS uid', 'm.number AS mnumber')
                  -&gt;where('m.is_active', '=', 1)
                  -&gt;orderBy('u.id', 'desc')
                  -&gt;get();
          if(count($robotlist)&gt;0){
          foreach ($robotlist as $v) {
  
              $robot_arr = [
              &quot;id&quot; =&gt; $v-&gt;uid,
              &quot;number&quot; =&gt; $v-&gt;mnumber,
              &quot;FA&quot; =&gt; $v-&gt;status_fa,
              &quot;FC&quot; =&gt; $v-&gt;status_fc,
              &quot;FM&quot; =&gt; $v-&gt;status_fm,
              &quot;PS&quot; =&gt; $v-&gt;status_ps
              ];
              $arr[]=$robot_arr;
          }}
  
          return $arr;
  
  
      }
  </code></pre>
  <p>Comment:</p>
  <p>Hello all,</p>
  <p><a href="https://stackoverflow.com/questions/55260821/laravel-join-two-tables-of-different-db-connections">Laravel : join two tables of different db connections</a></p>
  <p>I try to combine using the above code but it is fail.</p>
  <p>I have read the above link but it cannot reach my purpose as two table in different db in mysql.</p>
  <p>Please help me to solve the above problems.</p>
  <p>Thank you all.</p>