1

I've got a dynamic component which I am trying to pass an array of data to like:

<x-dynamic-component
            :component="$component['component']"
            :data="$component"
        />

However when I try and access $data from within my component blade view. $data is not an array, its and instance of Illuminate\View\DynamicComponent:

Illuminate\View\DynamicComponent {#1564 ▼ // resources/views/components/page-builder/test-one.blade.php
  #except: []
  +componentName: "dynamic-component"
  +attributes: Illuminate\View\ComponentAttributeBag {#1567 ▼
    #attributes: array:1 [▼
      "data" => Illuminate\View\DynamicComponent {#1564}
    ]
  }
  +component: "page-builder.test-one"
}

I've also tried:

    <x-dynamic-component
        :component="$component['component']"
        data="{{$component}}"
    />

but then I recieve

htmlspecialchars(): Argument #1 ($string) must be of type string, Illuminate\View\DynamicComponent given.

Any help on how I can pass an array of data to the view and how to access it would be much appreciated.

1 Answer 1

0

After further investigation I've managed to resolve the issue thanks to rodrigo.pedra answer at https://laracasts.com/discuss/channels/laravel/dynamic-blade

        @php
            $data =  \Illuminate\Support\Arr::get($component, 'data');
            dump($component['data']);
            dump($data);
        @endphp

        <x-dynamic-component
            :component="$component['component']"
            :props="$data"
        />

Even though $component['data'] and data are the same and both arrays, it appears that the blade component doesn't like passing through the array when accessing the array from the index :/

so setting the php like below works:

$data = $component['data']

or just passing $component into :props throws an error :/

I hope this helps someone :)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.