Hallo, controller
use Illuminate\Support\Facades\Response;
// Live Search
public function searching() {
$search_keyword = $_POST['search_keyword'];
$searchClients = DB::table('clients')->where('company',
$search_keyword)->get();
$bold_search_keyword = '<strong>' . $search_keyword . '</strong>';
$html = '';
if($searchClients) {
foreach ($searchClients as $rows) {
$html .= '<div class="show" align="left"><span class="name">' .
str_replace($search_keyword, $bold_search_keyword,
$rows['company']) . '</span></div>';
}
}
$result['html'] = $html;
return Response::json($result, 200, [], JSON_NUMERIC_CHECK);
}
JS
$(".search_keyword").keyup(function () {
var search_keyword_value = $(this).val();
var dataString = 'search_keyword=' + search_keyword_value;
if(search_keyword_value != '') {
$.ajax({
type: "POST",
url: "/searching",
data: dataString,
cache: false,
headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-
token"]').attr('content') },
success: function (response) {
$("#result").html(response.data.html).show();
},
error: function () {
alert('Not Okay');
}
});
}
return false;
});