How to access declared variable from laravel-livewire component in the app layout

I tried passing a variable from livewire component:

class Index extends Component
{
    public function render()
    {
        return view('livewire.index')->with('type', config('constants.NONAUTH'));
    }
}

and accessing it from layouts.app:

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">

{{dd($type)}}

@include('includes.head')

I get an error that $type is not defined, what is the correct way of doing this?

Hey @000kelvin,

I’d say you simply can’t. Looking at the Livewire src, each component is rendered in isolation. So anything you pass to your view is only available in that view.

The question is, what are you trying to achive? Maybe stacks can help you further.

I’m trying to include certain styles in the head tag based on type.
I’ve gone ahead with using custom layouts instead: https://laravel-livewire.com/docs/rendering-components#custom-layout