mirror of https://github.com/4xmen/xshop.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.4 KiB
PHTML
44 lines
1.4 KiB
PHTML
4 months ago
|
<?php
|
||
|
|
||
|
namespace App\Http\Middleware;
|
||
|
|
||
|
use App\Helpers\TVisitor;
|
||
|
use App\Models\Visitor;
|
||
|
use Closure;
|
||
|
use Illuminate\Http\Request;
|
||
|
use Symfony\Component\HttpFoundation\Response;
|
||
|
|
||
4 months ago
|
class VisitorCounter
|
||
4 months ago
|
{
|
||
|
/**
|
||
|
* Handle an incoming request.
|
||
|
*
|
||
|
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||
|
*/
|
||
|
public function handle(Request $request, Closure $next): Response
|
||
|
{
|
||
|
$visitor = Visitor::where('updated_at','>',date("Y-m-d H:i:s" ,time() - (60*60)))
|
||
|
->where('ip', $request->ip())->first();
|
||
|
if ($visitor === null) {
|
||
|
$visitor = new Visitor();
|
||
|
$visitor->ip = $request->ip();
|
||
4 months ago
|
$visitor->browser = TVisitor::DetectBrowser();
|
||
|
$visitor->os = TVisitor::DetectOS();
|
||
4 months ago
|
$visitor->version = TVisitor::BrowserVersion();
|
||
4 months ago
|
$ref = TVisitor::GetKeyword();
|
||
|
if ($ref !== null) {
|
||
|
$visitor->keywords = $ref['keyword'];
|
||
|
$visitor->engine = $ref['engine'];
|
||
|
}
|
||
4 months ago
|
$visitor->is_mobile = TVisitor::IsMobile();
|
||
4 months ago
|
$visitor->page = $request->route()->getName();
|
||
4 months ago
|
$visitor->save();
|
||
|
}else{
|
||
|
$visitor->increment('visit');
|
||
4 months ago
|
$visitor->page = $request->route()->getName();
|
||
|
$visitor->save();
|
||
4 months ago
|
}
|
||
|
return $next($request);
|
||
|
}
|
||
|
}
|