Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Developer.com's avatar

How to show array in blade view

im having out put like this

#original: array:30 [▼
        "id" => 124
        "call_id" => 1
        "user_id" => 1
        "crew_list" => "["Jehan","jerome"]"
        "update_user_id" => 0
        "created_at" => "2016-10-31 11:29:49"
        "updated_at" => "2016-10-31 14:30:16"
        "hv_id" => 1
      ]

im using foreach loop in my blade view

@foreach($transports as $key => $transport)
       <tr>
             <td> TRANSPORT : {{$transport->schedule_no}}</td>
              <td> {{ ($transport->crew_list)}}</td>
@endforeach

im getting this error

htmlentities() expects parameter 1 to be string, array given

can anyone tell idea ?

EDIT : in my controller i just checkd my output something wrong why is that ?

$transports = Transport::Where('call_id',$call->id)->get();
        foreach($transports as $transport){
            dd($transport);
        }
 #original: array:30 [▼
      "id" => 124
      "call_id" => 1
      "crew_list" => "["Jehan","jerome"]"
      "update_user_id" => 0
      "created_at" => "2016-10-31 11:29:49"
      "updated_at" => "2016-10-31 14:30:16"
      "hv_id" => 1
    ]

but when i check

foreach($transports as $transport){
            dd($transport->crew_list);
        }

its an empty array why is that ?

0 likes
16 replies
richard's avatar

You should display data as follows for arrays:

@foreach($transports as $transport)
       <tr>
             <td> TRANSPORT : {{$transport['schedule_no']}}</td>
              <td>
            @foreach ($transport['crew_list'] as $crew) 
                <li>{{ $crew }} </li>
            @endforeach
        </td>
@endforeach 
2 likes
popcone's avatar

$transport->crew_list is an array. So you should implode to display as string.

{{ implode(', ', $transport->crew_list)}}
2 likes
laravelMan's avatar

{!! implode(', ', json_decode($transport->crew_list)) !!}

1 like
popcone's avatar

yes.. like my previous reply {{ implode(', ', $transport->crew_list)}}

richard's avatar

@Developer.com this is not an array.

"crew_list" => "["Jehan","jerome"]"

An array looks like this

"crew_list" => ["Jehan","jerome"]

That is a string. Just use php string functions to split the contents.

You probably need to check out how you are saving the data into your database.

laravelMan's avatar

If implode() is not working, if it is treated as string you can try this as well.

{!! implode(', ', json_decode($transport->crew_list)) !!}

Please or to participate in this conversation.