[英]How to display values from Controller to Blade file in php laravel?
從控制器:
$response = (new ApiController)->checkNumbers();
if(!empty($response['status']) && ($response['status'] == 'SUCCESS')) {
$numbers = json_encode($response['numbers']);
}
return [
'html' => view('show.numbers', compact(
'numbers'
))->render()
];
如何在刀片文件中顯示“數字”以反映表格中的 UI? 任何幫助,將不勝感激。
非常感謝
這是一個關於如何從控制器傳遞數據並將其填充到刀片的示例。
例如,我有一個表:“用戶”,其中包含 id、firstname 和 lastname 列:
示例控制器.php
public function FetchUser(){
$data = User::all();
return view('MyView')->with([
'data' => $data
]);
}
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.