In Laravel 8, livewire2 I make a header component , which I call in
resources/views/layouts/frontpage.blade.php :
</head>
<body class="flex flex-col min-h-screen">
<header>
@livewire('app-header', ['layout'=>'frontend'])
</header>
<main class="frontend_page_container_wrapper z-20 ">
{{ $slot }}
</main>
<footer class="bg-green" style="height: 138px !important;">
@livewire('frontend-footer')
</footer>
@stack('modals')
@livewireScripts
</body>
</html>
To update current info in header when new page is opened in any component I call event of AppHeader component.
Like in app/Http/Livewire/Hostel/HostelsHomepageSpotlight.php :
<?php
namespace App\Http\Livewire\Hostel;
...
use Livewire\Component;
class HostelsHomepageSpotlight extends Component
{
...
public function render()
{
return view('livewire.hostel.hostels-homepage-spotlight', [
])->layout('layouts.frontpage');
} // public function render()
public function mount()
{
$this->hostelsDataRows = Hostel
::getByStatus('A')
...
->paginate($hostels_per_page);
...
\Log::info( varDump(-1, ' -1 HostelsHomepageSpotlight before setCurrentPageProperties::') );
// $this->emitUp('setCurrentPageProperties', [ // IF TO UNCOMMENT THIS LINE - IT DOES NOT WORK
$this->emitTo('AppHeaderAppHeader','setCurrentPageProperties', [
'layout' => "frontend",
'icon' => 'hostel',
'additive_class' => '',
'title' => 'Spotlight hostels',
'trigger_js_event' => true,
'template_container_id' => "hostels_homepage_spotlight_page_container"
]);
} // public function mount()
...
and in app/Http/Livewire/AppHeader.php :
<?php
namespace App\Http\Livewire;
use Livewire\Component;
class AppHeader extends Component
{
...
protected $listeners = ['setCurrentPageProperties' => 'setCurrentPagePropertiesCallback'];
public function render()
{
return view('livewire.app-header', [])
->layout('layouts.') ;//. $this->layout;
}
public function mount(
...
) {
...
}
public function setCurrentPagePropertiesCallback($data)
{
\Log::info(varDump($data, 'INSIDE -1 setCurrentPagePropertiesCallback $data::'));
if ( ! empty($data['layout'])) {
$this->layout = $data['layout'];
}
...
} // public function setCurrentPagePropertiesCallback($data)
}
When I open page with HostelsHomepageSpotlight.php component
I see degugging line
-1 HostelsHomepageSpotlight before setCurrentPageProperties
but not
INSIDE -1 setCurrentPagePropertiesCallback
as setCurrentPagePropertiesCallback method of HostelsHomepageSpotlight.php is not triggered.
How can it be fixed?
Thanks!