, @slot. , , .
:
Sometimes you may need to pass additional data to a component. For for this reason, you can pass an array of data as the second argument to the @component directive. All data will be available for the component template as variables:
@component('alert', ['foo' => 'bar'])
...
@endcomponent
So let's say you have a data array:
$my_array = ['a', 'b', 'c']
You can pass it to a component like this:
@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, in your component file, you will access the variable $my_array. For example, in a file, you can do this: contentheader.blade.php
<ul>
@foreach($my_array as $value)
<li>{{ $value }}</li>
@endforeach
</ul>
source
share