Laravel Blade: pass array as parameter to yield section

@yield produce a section, like an include but with the included template defined from the children

@yield does not accept parameters, and it makes sense since the parent does not have to knows what children will implement.

If you want to pass parameters to the template, an @include probably suits better the case

@include('subview', ['parameter_name' => 'parameter_value'])

Otherwise a simple php variable declared by the parent and used by the children can work with a @yield (and also with @include)

@php
$my_var='my_value'
@endphp
@yield('my_section')

If you want to send data from children to the parent, you can do it at the parent declaration, where you add it:

@extends('parent_view',['parameter_name'=>'parameter_value'])

You may use a separate file and include the file using @include while you may pass the data with a dynamic variable name so you'll be able to use that variable name in your included view, for example:

@include('view.name', ['variableName' => $array])

So, in the view.name view you can use/access the $array using $variableName variable and you are free to use any name for variableName.

So, in the separate view i.e: view.name, you may use a section and do whatever you want to do with $variableName.


Note: The problem was solved in the comment section but added as an answer here for the future reference so any viewer come here for similar problem will get the answer easily.