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

[7.x] Add getFirstWhereStartsWith() to ComponentAttributeBag #33358

Merged
merged 1 commit into from
Jun 29, 2020

Conversation

iAmKevinMcKee
Copy link
Contributor

Following up on the changes from earlier today, in order to effectively use this with Livewire we need to be able to get the first attribute value that starts with 'wire:model' so we can use that value for the error bag, among other reasons.

This function gives you the ability to do that. Your component would look like this:

Usage

<x-text-input wire:model.lazy="name" />

Blade Component

<div>
    <input type="text" {{$attributes->whereStartsWith('wire:model')}} />
    @error($attributes->getFirstWhereStartsWith('wire:model'))
        {{$message}}
    @enderror
</div>

Following up on the changes from earlier today, in order to effectively use this with Livewire we need to be able to get the attribute value that starts with 'wire:model' so we can use that value for the error bag, among other reasons.

This function gives you the ability to do that. Your component would look like this:

Usage
```html
<x-text-input wire:model.lazy="name" />
```

Blade Component
```php
<div>
    <input type="text" {{$attributes->whereStartsWith('wire:model')}} />
    @error($attributes->getFirstWhereStartsWith('wire:model'))
        {{$message}}
    @enderror
</div>
```
@GrahamCampbell GrahamCampbell changed the title Add getFirstWhereStartsWith() to ComponentAttributeBag [7.x] Add getFirstWhereStartsWith() to ComponentAttributeBag Jun 27, 2020
@taylorotwell
Copy link
Member

This returns the value and not the attribute key, correct?

@iAmKevinMcKee
Copy link
Contributor Author

iAmKevinMcKee commented Jun 29, 2020

Correct, in this example of <x-text-input wire:model.lazy="name" />, then $attributes->getFirstWhereStartsWith('wire:model') would return "name"

@taylorotwell taylorotwell merged commit 1a0c7b8 into laravel:7.x Jun 29, 2020
@taylorotwell
Copy link
Member

I just renamed the method to first so you can do {{ $attributes->thatStartWith('wire:model')->first() }}

@iAmKevinMcKee iAmKevinMcKee deleted the patch-2 branch June 29, 2020 16:41
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

Successfully merging this pull request may close these issues.

2 participants