Poldo
Poldo

Reputation: 1932

How to array data from @foreach in Laravel Views

I know this is possible but I've tried to search from the net but I've never found an answer so if anyone who knows how to push data to array from @foreach using Laravel View please help me. Thanks in advance

Here is the code

@foreach ($fields as $key => $rel)

 {{ $arrayData = array(

    'field_type' =>'$rel->field_type'
 )}}

@endforeach

The error I've receiving is

ErrorException in helpers.php line 519: htmlspecialchars() expects parameter 1 to be string, array given (View: C:\xampp\htdocs\fields.blade.php)

Upvotes: 0

Views: 1398

Answers (1)

Vision Coderz
Vision Coderz

Reputation: 8078

Remove quote from $rel->field_type

@foreach ($fields as $key => $rel)

 {{ $arrayData = array(

    'field_type' =>$rel->field_type
 )}}

@endforeach

Upvotes: 1

Related Questions