Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

daveb2's avatar

Access to slot attributes

Is it possible to access the attributes, specifically the class attribute, which is passed to a slot?

For example, say in a blade file I have:

component.blade.php

<div {{ $attributes->merge(['class' => 'default_classes']) }}>
	{{ $slot }}
	<div>
		<p>Some text here...</p>
		<div {{ $attributes->merge(['class' => 'footer_default_classes']) }}>
			{{ $footer }}
		</div>
	</div>
</div>

...and in another blade file I have:

another-component.blade.php (includes the blade component defined above)

<x-component class="override_classes">
	The content for the default slot
	<x-slot name="footer" class="footer_slot_override_classes">
		The content for the footer slot
	</x-slot>
</x-component>

The example above is of a blade component (component.blade.php) with multiple slots: the default slot, and another slot named "footer" (I realise there is a short-hand way to specify the slot name in laravel 9 with :name but my IDE only understands the old way currently). It is included from another-component.blade.php, from which I would like to pass in a class attribute for the footer slot (and potentially others).

How do I retrieve the $attributes array for the footer slot within component.blade.php ?

0 likes
1 reply
daveb2's avatar

Well, I'll be. It's right there in the documentation! https://laravel.com/docs/9.x/blade#slots

component.blade.php

<div {{ $footer->attributes->class(['footer_default_classes']) }}>

Sorry all, seems I'm always finding the answer right after I ask the question.

1 like

Please or to participate in this conversation.