LogPostRequest.php 997 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. namespace App\Http\Middleware;
  3. use App\Components\ErrorPush;
  4. use App\Services\LogService;
  5. use Closure;
  6. use Illuminate\Support\Facades\Auth;
  7. class LogPostRequest
  8. {
  9. use ErrorPush;
  10. /**
  11. * Handle an incoming request.
  12. *
  13. * @param \Illuminate\Http\Request $request
  14. * @param \Closure $next
  15. * @return mixed
  16. */
  17. public function handle($request, Closure $next)
  18. {
  19. try {
  20. if($request->method()!='GET'){
  21. LogService::log($request->fullUrl(),$request->method(),
  22. '请求:'.json_encode($request->all())
  23. .'请求头:'.json_encode($request->headers->all())
  24. );
  25. }
  26. return $next($request);
  27. }catch (\Exception $e){
  28. $this->push(__METHOD__."->".__LINE__,"路径跳转捕获",$e->getMessage()." 请求用户:".Auth::id()." request对象:".json_encode($request));
  29. return view("exception.404");
  30. }
  31. }
  32. }