繁体   English   中英

如何在 php laravel 中显示从 Controller 到 Blade 文件的值?

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

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