1

I am passing an array in Laravel blade template from controller. But it shows an error

Cannot use object of type stdClass as array

Here is the array which I passed to the view

[[{"id":10,"user_id":4,"service_speciality":"4","contact":"789","created_at":"2018-06-06 05:52:22","updated_at":"2018-06-06 05:52:22","branch_id":3,"name":"lene","doctor_email":"[email protected]","service_name":"Tooth pain"}],[{"id":8,"user_id":4,"service_speciality":"1","contact":"123","created_at":"2018-06-06 05:51:41","updated_at":"2018-06-06 05:51:41","branch_id":1,"name":"lene","doctor_email":"[email protected]","service_name":"Kneck pain"}]]

Here is my blade template view where I got error

@foreach($doctor as $datum)
<div id="pg-112-0" class="panel-grid panel-no-style col-lg-12">

@foreach($datum as $data)
<div id="pgc-112-0-0" class="panel-grid-cell col-lg-4">
  <div id="panel-112-0-0-0" class="so-panel widget widget_pw_person_profile widget-person-profile panel-first-child panel-last-child" data-index="0">

    <div class="person-profile h-card">

      <div class="person-profile__container">
        <div class="person-profile__basic-info">

          <h4 class="person-profile__name  p-name">
            <a href="{{ url('/doctor/'.str_slug($data["name"], "-").'-'.$data["id"] ) }}">
              Dr. {{ $data['name'] }}                                           
            </a>
          </h4>
          <div class="person-profile__label">
            {{ $data['service_name'] }} Specialist
          </div>
        </div>

        <a class="btn  btn-secondary  btn-block  person-profile__button" href="{{ url('/doctor/'.str_slug($data["name"], "-").'-'.$data["id"] ) }}" target="_self">Read More</a>

      </div>
    </div>
  </div>
</div>
@endforeach

</div>

@endforeach
4
  • 1
    $data['service_name'] should be $data->service_name, etc, etc. Commented Jul 17, 2018 at 10:22
  • 1
    Message is clear, isn't it? Commented Jul 17, 2018 at 10:23
  • 1
    use $var->property it will work Commented Jul 17, 2018 at 10:25
  • @u_mulder...ya message is clear.... i got that Commented Jul 17, 2018 at 10:31

1 Answer 1

6

The error massage says it all. Change your code from:

$data['SOMETHING'] 

To

$data->SOMETHING

Example from: $data['service_name'] to $data->service_name

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.