I am making a search and based on this i am returning some data via Jquery-Ajax There is no problem to display the data but i need them as paginated.
JQuery
$(document).ready( function() {
$(".client_search_option").change(function(){
var selectedClientTypeVal = "";
var selectedSmsDecisionVal = "";
var selectedClientType = $('input[type=radio][name=clientType]:checked');
var selectedSmsDecision = $('input[type=radio][name=sms_decision]:checked');
if (selectedClientType.length > 0) {
selectedClientTypeVal = selectedClientType.val();
}
if (selectedSmsDecision.length > 0) {
selectedSmsDecisionVal = selectedSmsDecision.val();
}
//alert(selectedClientTypeVal);
//alert(selectedSmsDecisionVal);
var CSRF_TOKEN = $('meta[name="csrf-token"]').attr('content');
$.ajax({
url: 'http://localhost/pages/clientSearchAjax',
type: 'POST',
data: {_token: CSRF_TOKEN, selectedClientTypeVal:selectedClientTypeVal,selectedSmsDecisionVal:selectedSmsDecisionVal},
dataType: 'JSON',
success: function (data) {
console.log(data);
},
error:function(){
alert("An error has occured !");
}
});
});
});
Controller
public function clientSearch(){
$client_option = Input::get('selectedClientTypeVal');
$sms_option = Input::get('selectedSmsDecisionVal');
if($client_option == 'all' && $sms_option == 'all'){
$ajax_clients = Client::with('clientType')->paginate(5);
}else{
$ajax_clients = Client::with('clientType')->where('clienttype_id', $client_option)->where('send_sms', $sms_option)->paginate(5);
}
return $ajax_clients->toJson();
}
How can i paginate this Ajax Response, any help would be appreciated.