I don't see anywhere in the documentation that it's possible to write $slot->withAttributes.
Where did you see this ?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi guys,
I hope this thread finds you well.
I was trying to make a component that generates locale-based inputs depending on the site configuration in my application, however I face difficulty when I was attempting to have the component generate multiple instances of the inputs by using the slots method.
To simplify lets say we have a x-fields component where it has the following content.
@php
$langs = ['en','jp'];
@endphp
<div class="container">
@foreach($langs as $lang)
{{ $slot->withAttributes(['lang' => $lang]) }}
@endforeach
</div>
And I was thinking of doing something like in page.blade.php:
<x-fields name="something">
<x-input :$lang />
</x-fields>
Which ideally gives me:
<div class="container">
<input name="something[en]" />
<input name="something[jp]" />
</div>
From my observation it seems like the slots were rendered before the for-loop happens and the variable not found error takes place for $lang.
May I ask if there's a better way of doing this, ideally within the scope of blade templates?
Thank you and have a wonderful day!
Please or to participate in this conversation.