在 laravel 5.1 中制作访客跟踪器
Making a visitor tracker in laravel 5.1
我目前安装了插件 (https://github.com/antonioribeiro/tracker)
哪个做跟踪的事情,只有我想获得唯一身份访问者。我真的不知道如何从这个包中提取那些。或者我应该如何自己制作一个。
我希望他们每月 return 作为 JSON 个对象。
如果有人可以帮我解决这个问题?
我尝试使用 tracker_sessions
table,但效果不佳。
Route::get('admin/api', function(){
$stats = DB::table('tracker_sessions')
->groupBy('created_at')
->orderBy('created_at', 'ASC')
->get([
DB::raw('created_at as y'),
DB::raw('COUNT(*) as b')
]);
return json_encode($stats);
});
那个 return 是这样的:
[{"y":"2016-05-22 21:17:17","b":1},{"y":"2016-05-22 21:17:27","b":1},{"y":"2016-05-22 21:17:28","b":2},{"y":"2016-05-22 21:17:29","b":1},{"y":"2016-05-22 21:17:31","b":1},{"y":"2016-05-22 21:17:33","b":1},{"y":"2016-05-22 21:18:10","b":1},{"y":"2016-05-22 21:18:11","b":2},{"y":"2016-05-22 21:18:13","b":1}]
一点都不好
Route::get('admin/api', function(){
$stats = DB::table('tracker_sessions')
->groupBy(DB::raw('CAST(created_at as DATE)'))
->orderBy(DB::raw('CAST(created_at as DATE)'))
->get([
DB::raw('CAST(created_at as DATE) as y'),
DB::raw('COUNT(DISTINCT ip_column) as b')
]
);
return json_encode($stats);
});
我目前安装了插件 (https://github.com/antonioribeiro/tracker)
哪个做跟踪的事情,只有我想获得唯一身份访问者。我真的不知道如何从这个包中提取那些。或者我应该如何自己制作一个。
我希望他们每月 return 作为 JSON 个对象。
如果有人可以帮我解决这个问题?
我尝试使用 tracker_sessions
table,但效果不佳。
Route::get('admin/api', function(){
$stats = DB::table('tracker_sessions')
->groupBy('created_at')
->orderBy('created_at', 'ASC')
->get([
DB::raw('created_at as y'),
DB::raw('COUNT(*) as b')
]);
return json_encode($stats);
});
那个 return 是这样的:
[{"y":"2016-05-22 21:17:17","b":1},{"y":"2016-05-22 21:17:27","b":1},{"y":"2016-05-22 21:17:28","b":2},{"y":"2016-05-22 21:17:29","b":1},{"y":"2016-05-22 21:17:31","b":1},{"y":"2016-05-22 21:17:33","b":1},{"y":"2016-05-22 21:18:10","b":1},{"y":"2016-05-22 21:18:11","b":2},{"y":"2016-05-22 21:18:13","b":1}]
一点都不好
Route::get('admin/api', function(){
$stats = DB::table('tracker_sessions')
->groupBy(DB::raw('CAST(created_at as DATE)'))
->orderBy(DB::raw('CAST(created_at as DATE)'))
->get([
DB::raw('CAST(created_at as DATE) as y'),
DB::raw('COUNT(DISTINCT ip_column) as b')
]
);
return json_encode($stats);
});