0

dd result I have an API resulted as in picture. And I want to show the result in Laravel Blade. So I use this code:

    @if(isset($data))
        @foreach ($data as $had)
            <tr>
            <th scope="row">#</td>
            dd({{ $had['data']['NoHdt'] }});
            <td>{{ $had['data']['NoHdt'] }}</td>
            <td>{{ $had['data']['Kitab'] }}</td>
            <td>{{ $had['data']['Isi_Indonesia'] }}</td>
            </tr>
        @endforeach
    @endif
  </tbody>

But it always resulted

Undefined index: data

How to make it right?

bandungeuy
  • 378
  • 4
  • 19
  • Does this answer your question? ["Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset" using PHP](https://stackoverflow.com/questions/4261133/notice-undefined-variable-notice-undefined-index-and-notice-undefined) – miken32 Jun 24 '21 at 19:22
  • Thanks to Davit, he gave me the right answer. – bandungeuy Jun 24 '21 at 21:56

2 Answers2

2

Try this

@foreach ($apiResult['data'] as $data)
    <tr>
        <th scope="row">#</td>
        <td>{{ $data['NoHdt'] }}</td>
        <td>{{ $data['Kitab'] }}</td>
        <td>{{ $data['Isi_Indonesia'] }}</td>
    </tr>
@endforeach

where $apiResult correspond your shared dd screen https://i.stack.imgur.com/YQWfi.png

Davit Zeynalyan
  • 8,418
  • 5
  • 30
  • 55
0

You can try the following instead.

@if(isset($data))
@foreach ($data as $had)
<tr>
    <th scope="row">#</td>
    dd({{ $had->NoHdt }});
    <td>{{ $had->NoHdt }}</td>
    <td>{{ $had->Kitab }}</td>
    <td>{{ $had->Isi_Indonesia }}</td>
</tr>
@endforeach
@endif
</tbody>
Karl Hill
  • 12,937
  • 5
  • 58
  • 95