I've recently started working with Laravel during one of my courses and those components look really promising. One problem though, that I've come across, is passing data from, let's say, the controller, to a nested component.
Here's my (oversimplified) setup:
mainframe.blade.php (used as my layout template) :
<body>
<!-- Navigation-->
<x-main-menu></x-main-menu>
<!-- Page Header-->
<x-master-header :headerText="$headerText"></x-master-header>
{{ $content }}
</body>
master-header.blade.php :
<header>
<h1>{{ $headerText }}</h1>
</header>
and finally, home.blade.php, that "extends" my layout page :
<x-mainframe>
<x-slot name="content">
*... some content*
</x-slot>
</x-mainframe>
Now, I thought that it would as trivial as simply passing the $headerText content through my controller, like so :
public function home() {
return view("home", [
"headerText" => "Je teste les variables des templates Blade"
]);
}
... but apparently, that variable is passed only to the initial "home" view, but not all the way through my header component as I'm getting an error.
I've been reading on View Composer as a solution, but I thought there might be a simpler way of doing that.
So, as asked in the title, how can I pass data from a grand parent component to one of his grand children component ?
Thanks !