title: How to display specific data of an SQL table using php blade
body: <p>I have a program where an user is assigned to a project which has images and texts. </p>
  
  <p>And obviously, in said program, an User can see the projects assigned to him and, by extension, the texts and images of the project. </p>
  
  <p>But I have problem, where, if one user has 2 projects, when he looks for one project, he sees the data of both of them, as you can see in the next image:</p>
  
  <p><img src="https://i.stack.imgur.com/Ga3la.png" alt="Example"></p>
  
  <p>As you can see, it's showing both text 1 and 2 which are "Cambio 3" and "Cambio 1" respectively, but, it should only show the first text. The code I have for this is:</p>
  
  <p>index_proyecto_blade.php</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;div class="row pt-4"&gt;
                      &lt;h3&gt;Textos&lt;/h3&gt;
  
                      @foreach($usuario_proyecto as $usr_prt)
  
                      @foreach($proyecto_data as $prt)
  
                      @foreach($texto_data as $txt)
  
                      @foreach($texto_proyecto_data as $txt_prt)
  
                          @if($txt_prt-&gt;id_texto_data == $txt-&gt;id)
  
                          @if($txt_prt-&gt;id_proyecto_data == $prt-&gt;id_proyecto)
  
                          @if($usr_prt-&gt;id_proyecto == $prt-&gt;id_proyecto)
  
                              Id de texto: {{ $txt-&gt;id }}
                              &lt;br&gt;
                              &lt;div class="col-2"&gt;
                                  &lt;h5&gt;{{ $txt-&gt;caption }}&lt;/h5&gt;
                                  &lt;p&gt;{{ $txt-&gt;texto }}&lt;/p&gt;
                              &lt;/div&gt;
                              &lt;br&gt;
                          @endif
                          @endif
                          @endif
                      @endforeach
                      @endforeach
                      @endforeach
                      @endforeach
                  &lt;/div&gt;
  </code></pre>
  
  <p>And here are the tables in play:</p>
  
  <p>Usuario_Proyecto (relation between user and a project)</p>
  
  <pre><code>Usuario_Proyecto::all()
  =&gt; Illuminate\Database\Eloquent\Collection {#3061
       all: [
         App\Usuario_Proyecto {#3069
           id: 1,
           id_user: 2,
           id_proyecto: 1,
           created_at: null,
           updated_at: null,
         },
         App\Usuario_Proyecto {#3062
           id: 2,
           id_user: 2,
           id_proyecto: 2,
           created_at: null,
           updated_at: null,
         },
       ],
     }
  </code></pre>
  
  <p>Proyecto_data (clone of an original project)</p>
  
  <pre><code>Proyecto_Data::all()
  =&gt; Illuminate\Database\Eloquent\Collection {#3060
       all: [
         App\Proyecto_Data {#3063
           id: 1,
           nombre_proyecto: "["proyecto_test"]",
           id_proyecto: 1,
           created_at: null,
           updated_at: null,
         },
         App\Proyecto_Data {#3058
           id: 2,
           nombre_proyecto: "["proyecto_test_2"]",
           id_proyecto: 2,
           created_at: null,
           updated_at: null,
         },
       ],
     }
  </code></pre>
  
  <p>Texto_Data (clone of a text associated to a project/text associatod to Proyecto_Data)</p>
  
  <pre><code>texto_data::all()
  [!] Aliasing 'texto_data' to 'App\texto_data' for this Tinker session.
  =&gt; Illuminate\Database\Eloquent\Collection {#3068
       all: [
         App\texto_data {#3069
           id: 1,
           nombre: "["this is a test caption"]",
           texto: "["Cambio 3"]",
           min: 1,
           max: 100,
           created_at: null,
           updated_at: null,
         },
         App\texto_data {#3070
           id: 2,
           nombre: "["palaBRA2"]",
           texto: "cambio 1",
           min: 1,
           max: 100,
           created_at: null,
           updated_at: null,
         },
       ],
     }
  </code></pre>
  
  <p>Texto_Proyecto_Data (Relation between texto_data and proyecto_data)</p>
  
  <pre><code>texto_proyecto_data::all()
  [!] Aliasing 'texto_proyecto_data' to 'App\texto_proyecto_data' for this Tinker session.
  =&gt; Illuminate\Database\Eloquent\Collection {#3071
       all: [
         App\texto_proyecto_data {#3050
           id: 1,
           id_texto_data: 1,
           id_proyecto_data: 1,
           created_at: null,
           updated_at: null,
         },
         App\texto_proyecto_data {#3045
           id: 2,
           id_texto_data: 2,
           id_proyecto_data: 2,
           created_at: null,
           updated_at: null,
         },
       ],
     }
  </code></pre>
  
  <p>The reason of why I use clones is because the user can edit their version of a project.</p>
  
  <p>I make sure (I think at least) that the program only shows the data if the proyecto_id of text is the same the one in proyect and user. But it still shows the ones the text of other projects. </p>
  
  <p>Why is that happening? I'm doing something wrong?</p>