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 blade attribute method whereDoesNotStartsWith(string) #33851

Merged
merged 2 commits into from Aug 13, 2020
Merged

[7.x] Add blade attribute method whereDoesNotStartsWith(string) #33851

merged 2 commits into from Aug 13, 2020

Conversation

bilfeldt
Copy link
Contributor

@bilfeldt bilfeldt commented Aug 13, 2020

This PR adds a method whereDoesNotStartsWith($string) which complements the whereStartsWith($string) for handling blade component attribute bags.

What is this used for?

In general this complements the whereStartsWith($string) so that one can easily split the attribute bag into two portions that can be handled differently.

One great example would be a Livewire compatible component like:

<x-custom-input wire:model="input" value="123"/>

Now a completely simplified version of this component could be something like:

// resources/views/components/custom-input.blade.php

<div {{-- This is an outer div and this is the one livewire should operate on - so all livewire stuff here --}}
    {{ $attributes->whereStartsWith('wire:') }}
>
    {{--
            Here can be any kind of stuff maybe using a lot of livewire, dispatching events
            and stopping other events from bubbling up.
    --}}

   <input {{ $attributes->whereDoesNotStartsWith('wire:')->merge(['class' => 'some-class']) }}/>
</div>

Alternatives

There is already a filter method, so essentially these two are identical:

{{ $attributes->whereDoesNotStartsWith('wire:') }}<!-- New proposed syntax -->
{{ $attributes->filter(fn ($value, $key) => ! \Illuminate\Support\Str::startsWith($key, 'wire:')) }}<!-- Already available -->

This change adds a method `whereDoesNotStartsWith($string)` which complements the `whereStartsWith($string)`
@bilfeldt bilfeldt changed the title Add method whereDoesNotStartsWith(string) Add blade attribute method whereDoesNotStartsWith(string) Aug 13, 2020
@driesvints driesvints changed the title Add blade attribute method whereDoesNotStartsWith(string) [7.x] Add blade attribute method whereDoesNotStartsWith(string) Aug 13, 2020
@taylorotwell taylorotwell merged commit f0572ff into laravel:7.x Aug 13, 2020
9 of 10 checks passed
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.

None yet

2 participants