[英]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.