Posts Learn Components Snippets Categories Tags About
/

How to Pass Data From Livewire Component to Layout Page

Learn how to pass data from the Livewire Component to Base Layout page using layoutData method

Created on Jul 31, 2021

136 views

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'])

Snippets by

PostSrc poster

PostSrc

Full stack developer mainly focusing on the front end side of the web. The main author of PostSrc and loves writing tutorial and guides online.

new

PostSrc Code Components

Collection of Tailwind CSS components for everyone to use. Browse all of the components that's right for your project.

View Components

Other Code Snippets

More