Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

yonka's avatar
Level 2

Search AutoComplete laravel livewire

I want to be able to search related tables I have Three Tables Item, InventoryItem and attributeValue

So I want to be able to search by Item_name with attributeValue in InventoryInStore which I am going to be able to select as autocomplete input. By using Laravel livewire

0 likes
1 reply
LaryAI's avatar
Level 58

To implement a search autocomplete feature using Laravel Livewire that allows you to search by item_name and attributeValue in InventoryInStore, you can follow these steps:

  1. Create a Livewire Component:

    First, create a Livewire component that will handle the search logic and display the results.

    php artisan make:livewire SearchAutocomplete
    
  2. Update the Livewire Component:

    In the SearchAutocomplete component, you will need to define the search logic. Here's an example of how you might implement it:

  3. Create the Blade View:

    Create a Blade view for the Livewire component. This view will include an input field for the search query and display the search results.

    <!-- resources/views/livewire/search-autocomplete.blade.php -->
    <div>
        <input type="text" wire:model="query" placeholder="Search items..." />
    
        @if(!empty($results))
            <ul>
                @foreach($results as $result)
                    <li>
                        {{ $result->inventoryItem->item->item_name }} - 
                        @foreach($result->inventoryItem->attributeValues as $attributeValue)
                            {{ $attributeValue->attribute_value_name }}
                        @endforeach
                    </li>
                @endforeach
            </ul>
        @endif
    </div>
    
  4. Include the Livewire Component in Your View:

    Finally, include the Livewire component in the view where you want the search functionality to appear.

    <!-- In your Blade view -->
    @livewire('search-autocomplete')
    
  5. Ensure Livewire is Set Up:

    Make sure you have Livewire set up in your Laravel application. You can follow the Livewire installation guide if you haven't done so already.

This setup will allow you to search for items by item_name and attributeValue in the InventoryInStore model, and display the results in an autocomplete dropdown. Adjust the query logic as needed to fit your specific requirements.

Please or to participate in this conversation.