[英]How to display values from Controller to Blade file in php laravel?
From Controller:从控制器:
$response = (new ApiController)->checkNumbers();
if(!empty($response['status']) && ($response['status'] == 'SUCCESS')) {
$numbers = json_encode($response['numbers']);
}
return [
'html' => view('show.numbers', compact(
'numbers'
))->render()
];
How I can show "numbers" in blade file to reflect on UI in table ?如何在刀片文件中显示“数字”以反映表格中的 UI? Any help would be appreciated.
任何帮助,将不胜感激。
Many Thanks非常感谢
Here's an example on how you can pass data from your controller and populate it to your blade.这是一个关于如何从控制器传递数据并将其填充到刀片的示例。
For example I have a table: 'user' with columns id,firstname and lastname:例如,我有一个表:“用户”,其中包含 id、firstname 和 lastname 列:
SampleController.php示例控制器.php
public function FetchUser(){
$data = User::all();
return view('MyView')->with([
'data' => $data
]);
}
MyView.blade.php MyView.blade.php
{{-- populate it in a table --}}
<table class="table">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">First</th>
<th scope="col">Last</th>
</tr>
</thead>
<tbody>
@foreach($data as $item){
<tr>
<td>{{$item->id}}</td>
<td>{{$item->firstname}}</td>
<td>{{$item->lastname}}</td>
</tr>
}
</tbody>
</table>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.