Php Laravel活动日志使用Ajax Jquery分页
我试图通过laravel检索用户的活动日志,我可以毫无问题地检索数据,但我想用jquery对这些数据进行分页,因为我是通过ajax检索的,这是我的控制器代码Php Laravel活动日志使用Ajax Jquery分页,php,jquery,ajax,laravel,Php,Jquery,Ajax,Laravel,我试图通过laravel检索用户的活动日志,我可以毫无问题地检索数据,但我想用jquery对这些数据进行分页,因为我是通过ajax检索的,这是我的控制器代码 public function get_activities(Request $request){ $id=$request->client_id; >where('subject_type','App\Models\Comment')->get(); $client=Client::
public function get_activities(Request $request){
$id=$request->client_id;
>where('subject_type','App\Models\Comment')->get();
$client=Client::find($id);
$data = Activity::with('causer')->forSubject($client)->orWhere(function($query) use ($client) {
$query
->where('subject_type', (new Comment())->getMorphClass())
->whereIn('subject_id', $client->comments()->pluck('comments.id'));
})->paginate(200);
foreach ($data as $log) {
$msgArray = array();
$msg="";
if (isset($log->properties['old'])) {
foreach ($log->properties['old'] as $key => $value) {
$oldkey = $key;
$oldval = $value;
foreach ($log->properties['attributes'] as $key => $value) {
if($key==$oldkey) {
$newval = $value;
$msg = $oldkey . ' Changed from <code class="activity_code">'. $oldval .'</code>' .'to <code class="activity_code">' . $newval . "</code>";
array_push($msgArray,$msg);
}
}
}
} else {
foreach ($log->properties['attributes'] as $key => $value) {
$msg ="";
}
}
$log->msg=$msgArray;
}
return $data;
}
这是我在视图中显示数据的方式
功能填充\客户\活动(){
var id=$('#client_id').val()
$.ajax({
url:“/Clients/get_活动”,
方法:“获取”,
标题:{
“X-CSRF-TOKEN”:CSRF
},
数据:{client_id:id},
数据类型:“json”,
成功:功能(res){
console.log(res)
var数据=资源数据;
$('#客户端活动表').html(“”)
data.forEach(功能(obj){
已检查var_var=''
var messages=“”;
var msgarray=obj.msg;
变量paginate=obj.links;
msgarray.forEach(函数(项){
消息+=''+项+' '
});
console.log(消息)
var htmlq='\n+
“- \n”+
“\n”+
“\n”+
“\n”+
''+obj.causer.name+''+obj.description+''+obj.log_name+'#'+obj.subject_id+'\n'+
“
\n”+
信息+'
'+
“
”
var html='- '+obj.comment+
“+obj.diff+”
”;
$('#客户端活动表')。追加(htmlq)
feather.replace()
})
},
错误:函数(res){
}
});
}
我想在查看页面中添加分页,那么如何使用jquery实现这一点呢
"first_page_url": "http://localhost:86/Clients/get_activities?page=1",
"from": 1,
"last_page": 1,
"last_page_url": "http://localhost:86/Clients/get_activities?page=1",
"links": [
{
"url": null,
"label": "« Previous",
"active": false
},
{
"url": "http://localhost:86/Clients/get_activities?page=1",
"label": "1",
"active": true
},
{
"url": null,
"label": "Next »",
"active": false
}
],
"next_page_url": null,
"path": "http://localhost:86/Clients/get_activities",
"per_page": 200,
"prev_page_url": null,
"to": 23,
"total": 23
}
$.ajax({
url: "/Clients/get_activities",
method: "get",
headers: {
'X-CSRF-TOKEN': csrf
},
data:{client_id:id},
dataType: "json",
success: function (res) {
console.log(res)
var data=res.data;
$('#client_activity_table').html('')
data.forEach(function(obj) {
var checked_var=' '
var messages="";
var msgarray=obj.msg;
var paginate=obj.links;
msgarray.forEach(function(item) {
messages+='<li>'+item+'</li>'
});
console.log(messages)
var htmlq= '<ul class="customers-activity-history-list" id="leads_activity_history_list_33"> \n' +
'<li class="clearfix customer-activity-log-item" style="">\n' +
' <div class="pull-left customer-activity-log-avatar">\n' +
' </div>\n' +
' <div class="pull-left customer-activity-log-message-text">\n' +
' <span class="message-content"><b>'+obj.causer.name+'</b> ' +obj.description+'</b> '+obj.log_name+' <b> #'+obj.subject_id+'</b>\n' +
'<ul>\n' +
messages + ' </ul></span></div></li></div>'+
'<hr>'
var html= '<li class="list-group-item">'+obj.comment+
'<span>'+obj.diff+'</span></li>';
$('#client_activity_table').append(htmlq)
feather.replace()
})
},
error: function (res) {
}
});
}