1
votes

I have a view in blade that need a certain data from an api, if i dd the value it will give me a correct value that i need, but if i try to echo the value, then it will popup this error Undefined property: stdClass::$data

this is my code in blade view

@php
  $a = new stdClass();
  $a = $vehicleController::getDriverName($vehicle->driver_id)->data[0]->name;
  echo $a;
@endphp

this is the value if i dd($a) https://i.stack.imgur.com/3v7VM.png

this is the full data https://i.stack.imgur.com/f9Kyu.png

1

1 Answers

1
votes

I don't see why you would want to use echo to display the data in a blade. You should avoid putting your application logic in the views. Instead, consider calling the getDriverName method before returning the view and then pass the data to the blade as described in the documentation here: https://laravel.com/docs/8.x/blade#passing-data-to-components

When done correctly you can access the data in your blade like this:

<div>
    {{ $vehicle->data[0]->name }}
</div>