As far as I know, it isn't possible to pass an array to a component via @slot
. However, it is possible to pass and an array to a component directly, without using a slot.
From the documentation:
Passing Additional Data To Components
Sometimes you may need to pass additional data to a component. For
this reason, you can pass an array of data as the second argument to
the @component directive. All of the data will be made available to
the component template as variables:
@component('alert', ['foo' => 'bar'])
...
@endcomponent
So let's say you have an array of data:
$my_array = ['a', 'b', 'c']
You can pass it to the component like so:
@component('mylayouts.partials.contentheader', ['my_array' => $my_array])
...
@endcomponent
Or you can just pass it directly, without using a variable:
@component('mylayouts.partials.contentheader', ['my_array' => ['a', 'b', 'c']])
...
@endcomponent
Then, within your component file, you will have access to a $my_array
variable. For example, in your contentheader.blade.php
file you can do this:
<ul>
@foreach($my_array as $value)
<li>{{ $value }}</li>
@endforeach
</ul>