> Add Route with parameter in api.php file Laravel framework
Route::get('test', [
'as' => 'test',
'uses' => 'Front\TestController@extra'
])->name('test');
> Make simple API using Jquery Ajax
$("#<Your Element ID>").on('change keydown paste input', function(event) {
$.ajax({
url: '/api/test/?q='+event.target.value,
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
method: 'GET',
dataType: 'json',
beforeSend: function() {
}
}).done(function (data) {
console.log(data);
});
});
> Here is TestController.php
public function extra(Request $request) {
\Log::info($request->query('q'));
}