Skip to content

Commit 1a0c7b8

Browse files
Add getFirstWhereStartsWith() to ComponentAttributeBag
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> ```
1 parent 07ee3e8 commit 1a0c7b8

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/Illuminate/View/ComponentAttributeBag.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,30 @@ public function thatStartWith($string)
117117
{
118118
return $this->whereStartsWith($string);
119119
}
120+
121+
/**
122+
* Get the first attribute that starts with the given value from the attribute array.
123+
*
124+
* @param string $string
125+
* @param mixed $default
126+
* @return mixed
127+
*/
128+
public function getFirstWhereStartsWith($string, $default = null)
129+
{
130+
return $this->whereStartsWith($string)->getIterator()->current() ?? value($default);
131+
}
132+
133+
/**
134+
* Get the first attribute that starts with the given value from the attribute array.
135+
*
136+
* @param string $string
137+
* @param mixed $default
138+
* @return mixed
139+
*/
140+
public function getFirstThatStartsWith($string, $default = null)
141+
{
142+
return $this->getFirstWhereStartsWith($string, $default);
143+
}
120144

121145
/**
122146
* Exclude the given attribute from the attribute array.

0 commit comments

Comments
 (0)