1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
- namespace App\Http\Middleware;
- use App\Models\UsersLog;
- use Carbon\Carbon;
- use Closure;
- use Illuminate\Contracts\Auth\Factory as Auth;
- use Illuminate\Database\Eloquent\Model;
- use Jenssegers\Agent\Facades\Agent;
- use Zhuzhichao\IpLocationZh\Ip;
- use Illuminate\Support\Facades\Log;
- class RequestLogMiddleware
- {
- /**
- * The authentication guard factory instance.
- *
- * @var \Illuminate\Contracts\Auth\Factory
- */
- protected $auth;
- /**
- * Create a new middleware instance.
- *
- * @param \Illuminate\Contracts\Auth\Factory $auth
- * @return void
- */
- public function __construct(Auth $auth)
- {
- $this->auth = $auth;
- }
- /**
- * Handle an incoming request.
- *
- * @param \Illuminate\Http\Request $request
- * @param \Closure $next
- * @return mixed
- */
- public function handle($request, Closure $next)
- {
- // $ip=$request->header('ali-cdn-real-ip');
- // if (!$ip){
- // $ip = $request->header('X-Real-IP');
- // }
- // $address = Ip::find($ip);
- // $log = new UsersLog(); // 提前创建表、model
- // $log -> ip = $ip;
- // $log -> browser = Agent::browser(); // 浏览器名称
- // $log -> platform = Agent::platform();// 操作系统
- // $log -> device = Agent::device(); // 设备名称
- // $log -> address = $address[0].$address[1].$address[2];
- // $log -> is_phone = Agent::isPhone();
- // $log -> time = Carbon::now()->toDateTimeString();
- // $log -> created_at = Carbon::now()->toDateTimeString();
- // $log -> updated_at = Carbon::now()->toDateTimeString();
- // // 记录 用户信息
- // if($this->auth->check()) {
- // if($this->auth->user()->id) {
- // $log -> user_id = (int) $this->auth->user()->id ?? null;
- //// $log -> phone = $this->auth->user()->mobile ?? null;
- // $log -> nickname = $this->auth->user()->nickname ?? null;
- // }
- // }
- // // 记录 路由 方法 数据
- // $log -> path = $request->path();
- // $log -> method = $request->method();
- // $log -> input = json_encode($request->all(), JSON_UNESCAPED_UNICODE);
- // $log -> save(); # 记录日志
- return $next($request);
- }
- }
|