简体   繁体   中英

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 ? 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:

SampleController.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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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