1

I am kinda stuck, so I need you help.

I have an nested array that looks like this:

    array (size=2)
      0 => 
        array (size=5)
          'id' => int 7
          'name' => string 'sad' (length=3)
          'content' => string 'x' (length=1)
          'created_at' => string '2016-03-08 17:41:12' (length=19)
          'nm' => string 'test' (length=4)
      1 => 
        array (size=5)
          'id' => int 8
          'name' => string 'sadfafs' (length=7)
          'content' => string 'x' (length=1)
          'created_at' => string '2016-03-08 17:41:44' (length=19)
          'nm' => string 'test' (length=4)

I am trying to access data inside with this method:

@if ($forms != null)
         @foreach($forms as $forma)
             @foreach($forma as $form)
            <tr class="gradeA">
                  <td>{!! $form['id'] !!}</td>
                  <td>{!! $form['name'] !!}</td>
                  <td class="center">{!! $form['created_by'] !!}</td>
                  <td class="center">{!! $form['created_at'] !!}</td>
                  <td>
                      <a href="{{url('forms/delete?id=' . $form[0])}}">DELETE</a>
                      <a href="{{url('forms/edit?id=' . $form[0])}}">EDIT</a></td>
              </tr>
             @endforeach

         @endforeach
     @else
         <p> Nufing</p>
@endif

Whatever I am doing I get error: Illegal string offset "name"

Can someone advise me on how access this data in a correct manner?

2
  • you are getting id inside loop? Commented Mar 8, 2016 at 19:24
  • 2
    remove @foreach($forma as $form) and its closing @endforeach and it will work fine. check it Commented Mar 8, 2016 at 19:26

1 Answer 1

2

You need to remove inner foreach loop and every thing works fine. So code should be:-

@if ($forms != null)
         @foreach($forms as $forma)
            <tr class="gradeA">
                  <td>{!! $form['id'] !!}</td>
                  <td>{!! $form['name'] !!}</td>
                  <td class="center">{!! $form['created_by'] !!}</td>
                  <td class="center">{!! $form['created_at'] !!}</td>
                  <td>
                      <a href="{{url('forms/delete?id=' . $form[0])}}">DELETE</a>
                      <a href="{{url('forms/edit?id=' . $form[0])}}">EDIT</a></td>
              </tr>
         @endforeach
     @else
         <p> Nufing</p>
@endif
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.