customer = $customer; $this->route = $route; } public function handle() { $now = now(); $this->customer->last_using_api = $now; $this->customer->save(); $parts = explode(' ', $this->route); if (count($parts) < 2) { return; } $method = trim($parts[0]); $path = trim($parts[1]); $routeInfo = RouteInfo::where('method', $method) ->where('route', $path) ->first(); $lastlog = DB::table('customer_route_logs') ->where('customer_id', $this->customer->id) ->where('route', $this->route) ->where('last_using_api', '<', $now) ->orderBy('last_using_api', 'desc') ->first(); if ($lastlog) { $diff = Carbon::parse($lastlog->last_using_api)->diff($now); $timeSpentFormatted = sprintf('%02d:%02d:%02d', $diff->h + ($diff->d * 24), $diff->i, $diff->s); DB::table('customer_route_logs') ->where('id', $lastlog->id) ->update(['time_spent' => $timeSpentFormatted]); } DB::table('customer_route_logs')->insert([ 'customer_id' => $this->customer->id, 'route' => $this->route, 'route_info_id' => $routeInfo ? $routeInfo->id : null, 'last_using_api' => $now, 'time_spent' => null, ]); } }