Skip to content

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
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