title: Laravel explode and join
body: <p>I have a problem, I am requesting some data in the db and one of them are concatenated the field has form like this: </p>
  
  <pre><code> 1 | 2 | 3 | ... | n-1 | n,
  </code></pre>
  
  <p>The problem is that every numerical value I have to join with another table.</p>
  
  <pre><code>$Metro  = DB::table('fijacion')-&gt;where('tipo','Metro')-&gt;join('adp', 'fijacion.id', '=', "adp.id_fijacion")-&gt;get();
  </code></pre>
  
  <p>The solution that occurred to me was that chain divide it so</p>
  
  <pre><code>foreach($Metro as $Metro){ 
      $array = explode("|", $Metro-&gt;nr);
      $MetroXI = DB::table('users')
                -&gt;select('numero','nombre','apellido')
                -&gt;whereIn('numero',$array)
                -&gt;where('categoria', 1)
                -&gt;join('puntos', 'users.numero', '=', "puntos.nr")
                -&gt;orderBy('puntos.Total', 'asc')
                -&gt;get();
   }
  </code></pre>
  
  <p>This breaks the chain, but it only shows me a result</p>
  
  <p>I know it's confusing to understand but if someone could guide me how to make the forech correctly or some idea would be grateful</p>
  
  <p>$Metro:</p>
  
  <pre><code>[{"id":1,"semana":32,"fecha":"2017-08-11","dia":"Viernes","tipo":"Metro","categoria":null,"hora":"20:30 ","cancha":"CAPITOL ","partido":"CAPITOL \u2013 TABAR\u00c9 ","nr_1":null,"arbitro_1":null,"nr_2":null,"arbitro_2":null,"nr_3":null,"arbitro_3":null,"aux":1,"updated_at":"2017-08-07 12:04:04","created_at":"2017-08-07 12:03:57","id_fijacion":1,"nr":"7|22|29|31|32|40|53|59|66|67|68|77|5|12|13|17|18|20|24|27|28|33|35|37|44|46|50|52|61|64|65|75|23|25|26|39|47|48|51|58|69|74|80|82|83|86|93|96|104|109|117|120","designado":0},{"id":2,"semana":32,"fecha":"2017-08-11","dia":"Viernes","tipo":"Metro","categoria":null,"hora":"20:30 ","cancha":"MIRAMAR ","partido":"MIRAMAR \u2013 COL\u00d3N ","nr_1":null,"arbitro_1":null,"nr_2":null,"arbitro_2":null,"nr_3":null,"arbitro_3":null,"aux":1,"updated_at":"2017-08-07 12:04:04","created_at":"2017-08-07 12:03:57","id_fijacion":2,"nr":"7|22|29|31|32|40|53|59|66|67|68|77|5|12|13|17|18|20|24|27|28|33|35|37|44|46|50|52|61|64|65|75|23|25|26|39|47|48|51|58|69|74","designado":0},{"id":3,"semana":32,"fecha":"2017-08-11","dia":"Viernes","tipo":"Metro","categoria":null,"hora":"20:30 ","cancha":"SAYAGO ","partido":"ATENAS \u2013 AURIBLANCO ","nr_1":null,"arbitro_1":null,"nr_2":null,"arbitro_2":null,"nr_3":null,"arbitro_3":null,"aux":1,"updated_at":"2017-08-07 12:04:04","created_at":"2017-08-07 12:03:57","id_fijacion":3,"nr":"28|33|35|37|44|46|50|52|61|64|65|75|23|25|26|39|47|48|51|58|69|74|80|82|83|86|93|96|104|109|117|120","designado":0},{"id":4,"semana":32,"fecha":"2017-08-11","dia":"Viernes","tipo":"Metro","categoria":null,"hora":"20:30 ","cancha":"CORD\u00d3N \u2013 SIN P\u00daBLICO VISITANTE ","partido":"CORD\u00d3N \u2013 25 DE AGOSTO ","nr_1":null,"arbitro_1":null,"nr_2":null,"arbitro_2":null,"nr_3":null,"arbitro_3":null,"aux":1,"updated_at":"2017-08-07 12:04:05","created_at":"2017-08-07 12:03:57","id_fijacion":4,"nr":"7|22|29|31|32|40|53|59|66|67|68|77|5|12|13|17|18|20|35|37|44|46|50|52|61|64|65|75|23|25|26|39|47|48|51|58|69|74|80|82|83|86|93|96|104|109|117|120","designado":0},{"id":5,"semana":32,"fecha":"2017-08-11","dia":"Viernes","tipo":"Metro","categoria":null,"hora":"20:30 ","cancha":"STOCKOLMO ","partido":"STOCKOLMO \u2013 UNI\u00d3N ATL\u00c9TICA ","nr_1":null,"arbitro_1":null,"nr_2":null,"arbitro_2":null,"nr_3":null,"arbitro_3":null,"aux":1,"updated_at":"2017-08-07 12:04:05","created_at":"2017-08-07 12:03:57","id_fijacion":5,"nr":"7|22|29|31|32|40|53|59|66|67|68|77|5|12|13|17|18|20|24|27|28|33|35|37|44|46|50|52|61|64|65|75|23|25|26|39|47|83|86|93|96|104|109|117|120","designado":0}]
  </code></pre>
  
  <p>In the nr values is where I have to join it</p>
  
  <p>Thanks to @yoeunes loger avanasa but now in my view I have error.</p>
  
  <p>Which I realized I did not relate $ Metro with $ MetroXI [ ]</p>
  
  <p>Here are the parameters for my .blade
  This is my view:</p>
  
  <pre><code>                @foreach($Metro as $Metro)
                      &lt;tr&gt;
                      &lt;th&gt;{{$Metro-&gt;dia}}&lt;/th&gt;
                      &lt;th&gt;{{$Metro-&gt;fecha}}&lt;/th&gt;
                      &lt;th&gt;{{$Metro-&gt;categoria}}&lt;/th&gt;
                      &lt;th&gt;{{$Metro-&gt;hora}}&lt;/th&gt;
                      &lt;th&gt;{{$Metro-&gt;cancha}}&lt;/th&gt;
                      &lt;th&gt;{{$Metro-&gt;partido}}&lt;/th&gt;
                      &lt;th&gt;@php$array = explode("|", $Metro-&gt;nr);$pepe = count($array);@endphp{{ $pepe }}&lt;/th&gt;
  
  
                      &lt;select class="form-control" name="select1" id="arbitro_1"&gt;
                          &lt;option selected="true" disabled="disabled"&gt;Selecione 1º Arbitro&lt;/option&gt;
                          &lt;option disabled="disabled"&gt;---Internacional---&lt;/option&gt;
                          @foreach($MetroXI as $MetroXI)
                            &lt;option value="{{$MetroXI-&gt;numero}}"&gt;{{$MetroXI-&gt;nombre}}. {{$MetroXI-&gt;apellido}}&lt;/option&gt;
                          @endforeach
                      &lt;/select&gt;
  
          @endforeach
  </code></pre>
  
  <p>The error you give me is:</p>
  
  <blockquote>
    <p>Property [nr] does not exist on this collection instance.</p>
  </blockquote>
  
  <p>And occurs with the 3 variables.</p>