Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Passing $attributes to component slot does not work #52082

Closed
@KhizarWahabKhan

Description

@KhizarWahabKhan

Laravel Version

11

PHP Version

8.3.1

Database Driver & Version

Mysql

Description

Component slots can accept attributes but throws the following error when when passed all attributes through $attribute variable:
Illuminate\View\ComponentSlot::withAttributes(): Argument #1 ($attributes) must be of type array, null given,

Steps To Reproduce

This works when attributes are given manually the x-title:slot:

<x-alert {{ $attributes->twMerge('relative w-full rounded-lg border bg-white p-4 [&>svg]:absolute [&>svg]:text-foreground [&>svg]:left-4 [&>svg]:top-4 [&>svg+div]:translate-y-[-3px] [&:has(svg)]:pl-11 text-neutral-900') }}>
    @if ($title && !$title->isEmpty())
        <x-slot:title class="mb-1 font-medium leading-none tracking-tight">{{ $title }}</x-slot:title>
    @endif
</x-alert>

But this does not work, here the attribute bag is passed to the x-slot:title with default classes. It works on the main component x-alert but does not work on the slot:

<x-alert {{ $attributes->twMerge('relative w-full rounded-lg border bg-white p-4 [&>svg]:absolute [&>svg]:text-foreground [&>svg]:left-4 [&>svg]:top-4 [&>svg+div]:translate-y-[-3px] [&:has(svg)]:pl-11 text-neutral-900') }}>
    @if ($title && !$title->isEmpty())
        <x-slot:title {{ $title->attributes->twMerge('mb-1 font-medium leading-none tracking-tight') }}>{{ $title }}</x-slot:title>
    @endif
</x-alert>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions