mercredi 28 mars 2018

How to search autocomplete with laravel?

I'm trying to do search autocompleete in a taable with laaravel. I've triied to do thiis usiing the code below but nothiing happens....... Could you please help me with this....... Thank you in advance....

route.php

Route::get('/metier', 'MetierController@index');
Route::get('/metier/search', 'MetierController@search');
metiercontroller

public function index()
{
$Listmetier=metier::all();
return view('metier.index',['metier'=>$Listmetier]);
}
public function search(Request $request)
{     
if($request->ajax())
{
$output="";
$metiers=DB::table('metiers')- 
>where('libelle_metier','LIKE','%'.$request->search."%")-
>get();
if($metiers)
{
foreach ($metiers as $key => $metiers) {
$output.='<tr>'.
'<td>'.$metiers->id.'</td>'.
'<td>'.$metiers->libelle_metier.'</td>'.
'</tr>';
 }
 return Response($output);
}
}

index.blade.php

@extends('Layouts.app')
@extends('Layouts.master')
@section('content')
<link rel="stylesheet" type="text/css"     
 ref="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

Liste des Metiers Ajouter Metier

        <head>
        <tr>
            <th>libelle metier</th>
            <th>Action</th>

        </tr>
        </head>
        <body>

        </body>
    </table>

</div>
<script type="text/javascript">
    $('#search').on('keyup',function){
        $value=$(this).val();
        $.ajax({
            type: 'get',
            url : '',
            data : {'search':$value},
            success:function(data){
                console.log(data);
            } 
        });
    }
</script>
</div>
</div>
 @endsection



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2GeID8v
via IFTTT

Aucun commentaire:

Enregistrer un commentaire