Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel 8 pass attributes down to nested components #36225

Closed
Swanty opened this issue Feb 11, 2021 · 2 comments
Closed

Laravel 8 pass attributes down to nested components #36225

Swanty opened this issue Feb 11, 2021 · 2 comments

Comments

@Swanty
Copy link

Swanty commented Feb 11, 2021

EDIT: Fixed in #36240 (available from laravel v8.28.1)

  • Laravel Version: 8.20.1
  • PHP Version: 8.0.1
  • Database Driver & Version: N/A

Description:

I have 2 components and I am trying to pass down attributes from one component to the other.

Steps To Reproduce:

File: resources/views/home.blade.php

<x-form-input name="username" />

File: resources/views/components/form-input.blade.php

<x-input type="text" {{ $attributes }} />

File: resources/views/components/input.blade.php

@php
dd($attributes);
@endphp

<input {{ $attributes }} />

Output:

Illuminate\View\ComponentAttributeBag {#1451 ▼
  #attributes: array:1 [▼
    "name" => "username"
  ]
}

As you can see only 1 attribute is outputted even though form-input component added extra atribute type="text"
Expected result should of been 2 attributes type and name

I also tried putting :attributes="$attributes" instead of {{ $attributes }}, but same problem occurs.

Am I doing something wrong or not understanding how the attributes work?

@driesvints
Copy link
Member

This isn't supported atm but will be supported in Laravel 9.

@rodrigopedra
Copy link
Contributor

@Swanty as a workaround until Laravel 9 is released try this:

<x-input {{ $attributes->merge(['type' => 'text']) }} />

https://laravel.com/docs/8.x/blade#non-class-attribute-merging

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants