Laravel - Blade Templates - Filtering Attributes

You may filter attributes using the filter method. This method accepts a closure which should return true if you wish to retain the attribute in the attribute bag:

    
    {{ $attributes->filter(fn ($value, $key) => $key == 'foo') }}
	

For convenience, you may use the whereStartsWith method to retrieve all attributes whose keys begin with a given string:

    
    {{ $attributes->whereStartsWith('wire:model') }}
	

Conversely, the whereDoesntStartWith method may be used to exclude all attributes whose keys begin with a given string:

    
    {{ $attributes->whereDoesntStartWith('wire:model') }}
	

Using the first method, you may render the first attribute in a given attribute bag:

    
    {{ $attributes->whereStartsWith('wire:model')->first() }}
	

If you would like to check if an attribute is present on the component, you may use the has method. This method accepts the attribute name as its only argument and returns a boolean indicating whether or not the attribute is present:

    
    @if ($attributes->has('class'))
        
Class attribute is present
@endif

You may retrieve a specific attribute's value using the get method:

    
    {{ $attributes->get('class') }}