agent = new Agent(); $this->agent->setUserAgent($resource->user_agent); parent::__construct($resource); } /** * Transform the resource into an array. * * @param \Illuminate\Http\Request $request * @return array */ public function toArray($request) { return [ 'id' => $this->id, 'ip_address' => $this->ip_address, 'user_agent' => $this->user_agent, 'browser' => $this->agent->browser(), 'platform' => $this->agent->platform(), 'device' => $this->agent->deviceType(), 'login_at' => $this->login_at ? Carbon::parse($this->login_at)->toDayDateTimeString() : null, 'logout_at' => $this->logout_at ? Carbon::parse($this->logout_at)->toDayDateTimeString() : null, 'login_successful' => $this->login_successful, 'duration' => $this->logout_at ? Carbon::parse($this->logout_at)->diffForHumans(Carbon::parse($this->login_at), ['syntax' => CarbonInterface::DIFF_ABSOLUTE]) : null, 'login_method' => $this->login_method, ]; } }