Home / Snippets / How to Pass Data From Livewire Component to Layout Page
How to Pass Data From Livewire Component to Layout Page cover

How to Pass Data From Livewire Component to Layout Page

3.4K

2 years ago

0 comments

To pass data from the Livewire Component to the Layout file it's extending, you can make use of the "layoutData()" method.
return view('posts.show')
    ->layoutData(['title' => 'Show Posts'])

Now from the layouts page, you can access the "title" variable but do note to check if the value exists using "isset()" directive like below.
@isset($title)
    <h1>{{ $title }}</h1>
@endisset

If you prefer to provide a different layout page then you can use the "layouts()" method like below.
return view('posts.show')
    ->layout('layouts.base', ['title' => 'Show Posts'])
notion avatar

Ahabz

Week-end developer currently experimenting with web, mobile, and all things programming.

Topics:

Frontend

Resource

Average

Average

Support Us

If you like our tutorial, support us by being our Patreon or buy us some coffee ☕️

Welcome to PostSrc V3

PostSrc Dark Logo

You have to login to favorite this