lundi 22 juin 2020

Laravel Group by name

i have added a text box where it gives suggestions from the database when a user starts typing in it. and if there is similar names in the database column it suggests all the names by repeating. is there any way that i can suggest only one from the similar, when a user starts typing.

This is how it shows now when a user types col it shows colombo many times

Is there any way that i can solve this issue ?

// ! Autocompletion
function auto(Request $request)
{
    if($request->get('query'))
    {
        $query = $request->get('query');
        $data = DB::table('store_food_city_new')
            ->where('district', 'LIKE', "%{$query}%")
            ->get();
        $output = '<ul class="dropdown-menu" style="display:block; position:relative">';
        foreach($data as $row)
        {
            $output .= '<li><a href="#">'.$row->district.'</a></li>';
        }
        $output .= '</ul>';
        echo $output;
    }
}

Here's my Web.php

Route::post('store-locator/auto', 'Test\AllTestController@auto')->name('autocomplete.auto');

Here's my View

<div class="container box">
    <h3 align="center">Ajax Autocomplete Textbox in Laravel using JQuery</h3><br />
    <div class="form-group">
        <input type="text" name="country_name" id="country_name" class="form-control input-lg" placeholder="Enter Country Name" />
        <div id="countryList"></div>
    </div>
    
</div>


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire