Laravel Blade: pass array as parameter to yield section Laravel Blade: pass array as parameter to yield section laravel laravel

Laravel Blade: pass array as parameter to yield section


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.


You cannot pass parameters to the sections, but since the @yield logic is all about be nested in a parent, where the variable is used, the parameter has to be passed to the parent declaration, where you add it:

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