How can I pass an array variable in a Laravel component?

I want to pass array variable to my component.

Here is my code:

    $breadcrumbs = [
        'name' => 'Trainees',
        'link' => route('trainee.list')


When I try to access $breadcrumbs it says undefined variable.

>Solution :

You can pass an array to your component like this,

<x-breadcrumbs :breadcrumbs="$breadcrumbs"/>

If you want to pass simple string data,

<x-breadcrumbs value="Example String"/>

you have to define these variables in the component’s constructor except if it is an anonymous component.

you can check doc for more detailed info :

Leave a Reply