[英]How to display specific data of an SQL table using php blade
我有一个程序,其中用户被分配到一个包含图像和文本的项目。
显然,在所述程序中,用户可以看到分配给他的项目,以及项目的文本和图像。
但我有一个问题,如果一个用户有 2 个项目,当他查找一个项目时,他会看到两个项目的数据,如下图所示:
如您所见,它同时显示了文本 1 和 2,分别是“Cambio 3”和“Cambio 1”,但是,它应该只显示第一个文本。 我的代码是:
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>
以下是正在使用的表:
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(原始项目的克隆)
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(与项目关联的文本的克隆/与 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(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,
},
],
}
我使用克隆的原因是因为用户可以编辑他们的项目版本。
我确保(至少我认为)该程序仅在 text 的 proyecto_id 与 proyect 和 user 中的相同时才显示数据。 但它仍然显示其他项目的文本。
为什么会这样? 我做错了什么?
文件名不对。
index.blade.php
在您的控制器中,返回视图,如return view('proyecto.index');
; 基本上folder.file
始终将文件命名为xxx.blade.php
希望它有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.