简体   繁体   English

如何使用php刀片显示SQL表的特定数据

[英]How to display specific data of an SQL table using php blade

I have a program where an user is assigned to a project which has images and texts.我有一个程序,其中用户被分配到一个包含图像和文本的项目。

And obviously, in said program, an User can see the projects assigned to him and, by extension, the texts and images of the project.显然,在所述程序中,用户可以看到分配给他的项目,以及项目的文本和图像。

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:但我有一个问题,如果一个用户有 2 个项目,当他查找一个项目时,他会看到两个项目的数据,如下图所示:

例子

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.如您所见,它同时显示了文本 1 和 2,分别是“Cambio 3”和“Cambio 1”,但是,它应该只显示第一个文本。 The code I have for this is:我的代码是:

index_proyecto_blade.php index_proyecto_blade.php

<div class="row pt-4">
                    <h3>Textos</h3>

                    @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->id_texto_data == $txt->id)

                        @if($txt_prt->id_proyecto_data == $prt->id_proyecto)

                        @if($usr_prt->id_proyecto == $prt->id_proyecto)

                            Id de texto: {{ $txt->id }}
                            <br>
                            <div class="col-2">
                                <h5>{{ $txt->caption }}</h5>
                                <p>{{ $txt->texto }}</p>
                            </div>
                            <br>
                        @endif
                        @endif
                        @endif
                    @endforeach
                    @endforeach
                    @endforeach
                    @endforeach
                </div>

And here are the tables in play:以下是正在使用的表:

Usuario_Proyecto (relation between user and a project) Usuario_Proyecto(用户和项目之间的关系)

Usuario_Proyecto::all()
=> 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,
       },
     ],
   }

Proyecto_data (clone of an original project) Proyecto_data(原始项目的克隆)

Proyecto_Data::all()
=> 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,
       },
     ],
   }

Texto_Data (clone of a text associated to a project/text associatod to Proyecto_Data) Texto_Data(与项目关联的文本的克隆/与 Proyecto_Data 关联的文本)

texto_data::all()
[!] Aliasing 'texto_data' to 'App\texto_data' for this Tinker session.
=> 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,
       },
     ],
   }

Texto_Proyecto_Data (Relation between texto_data and proyecto_data) Texto_Proyecto_Data(texto_data 和 proyecto_data 之间的关系)

texto_proyecto_data::all()
[!] Aliasing 'texto_proyecto_data' to 'App\texto_proyecto_data' for this Tinker session.
=> 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,
       },
     ],
   }

The reason of why I use clones is because the user can edit their version of a project.我使用克隆的原因是因为用户可以编辑他们的项目版本。

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.我确保(至少我认为)该程序仅在 text 的 proyecto_id 与 proyect 和 user 中的相同时才显示数据。 But it still shows the ones the text of other projects.但它仍然显示其他项目的文本。

Why is that happening?为什么会这样? I'm doing something wrong?我做错了什么?

the file name isn't right.文件名不对。

index.blade.php

In your controller, return view like return view('proyecto.index');在您的控制器中,返回视图,如return view('proyecto.index'); ; ; Basically folder.file基本上folder.file

Always name the files xxx.blade.php始终将文件命名为xxx.blade.php

Hope it helped.希望它有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM