简体   繁体   English

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

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

相关问题 如何在Laravel中显示从控制器到刀片的数据? - How to display data from controller to blade in laravel? 我想从 Controller 访问 object 到 Laravel 刀片文件的值 - I want to access the values of an object to Laravel Blade file from Controller 如何在 Laravel 刀片中检索(在控制器中)和显示视频 - How to retrieve(in controller) and display video in a Laravel Blade 如何在 Laravel 的刀片视图中显示数据库中的 html 值? - how to display html values from a database in a blade view in Laravel? 如何将刀片文件中的集合或数组传递给 laravel 中的 controller? - How to pass a collection or array from blade file to controller in laravel? 如何将数据从刀片文件传递到Laravel中的Controller - how to pass data from blade file to Controller in Laravel 如何将数组数据从 controller 传递到刀片文件 Laravel - How to pass an array data from controller to blade file Laravel 如何从控制器发送数据到包含/头刀片文件,但在 Laravel 中返​​回另一个刀片文件 - how to send data from controller to include/header blade file but return another blade file in laravel laravel将数据从刀片文件传递到控制器 - laravel pass data from blade file to Controller Laravel 如何在blade中显示数组的键值 - Laravel how to display the key values of array in blade
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM