title: Response Server duration in Laravel Middleware
body: <p>I am Trying to get the response Server Duration in my Middelware and save it in Sql DataBase , Here is my middelware</p>
  <pre><code>public function handle(LaravelRequest $request, Closure $next)
      {
         
          $this-&gt;startTime = microtime(true);
  
         return $next($request); 
      }
  
  </code></pre>
  <pre><code>class AfterMiddleware  {
       
      public function handle(LaravelRequest $request, Closure $next)
      {
          
          $response = $next($request);
          
          $request-&gt;fingerprint();
          $RequestSaving = new Request();
          $endpoint=Endpoint::where(&quot;url&quot;,$request-&gt;url())-&gt;firstOrCreate([&quot;url&quot;=&gt;$request-&gt;url()]);
          $RequestSaving-&gt;endpoint()-&gt;associate($endpoint);
          $RequestSaving-&gt;method = $request-&gt;getMethod();
          $RequestSaving-&gt;status = $response-&gt;Status();
          $RequestSaving-&gt;user_id = Auth::id();
          $RequestSaving-&gt;duration=microtime(true)-$this-&gt;startTime;
          $RequestSaving-&gt;result =$response-&gt;Content();
          $RequestSaving-&gt;save();   
  
          return $response;
      }
  
  }
  </code></pre>
  <p>Everything works Fine only the part if the duration response that looks a littel bit complicated to me , Any ideas ?</p>