'array', 'prod_login' => 'array', 'https' => 'boolean' ]; /** * Map attribute names to enum classes. * * @var array */ protected $enumCasts = [ 'php' => PhpVersion::class, 'type' => ProjectType::class, 'smtp' => SmtpEnum::class ]; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'name', 'display_name', 'php', 'type', 'https', 'prod_haproxy_id', 'dev_haproxy_id', 'prod_url', 'dev_url', 'prod_document_root', 'dev_document_root', 'prod_unix_user', 'dev_unix_user', 'prod_unix_pwd', 'dev_unix_pwd', 'prod_db_user', 'dev_db_user', 'prod_db_pwd', 'dev_db_pwd', 'prod_db_schema', 'dev_db_schema', 'prod_db_server_id', 'dev_db_server_id', 'prod_web_server_id', 'dev_web_server_id', 'prod_comment', 'dev_comment', 'prod_eai', 'dev_eai', 'prod_whitelist_fw', 'dev_whitelist_fw', 'dev_htaccess_user', 'dev_htaccess_pwd', 'prod_ga_id', 'prod_laravel_app_key', 'dev_laravel_app_key', 'prod_smtp_config', 'prod_smtp_key', ]; /** * Get the route key for the model. * * @return string */ public function getRouteKeyName(): string { return 'uuid'; } // * METHODS /** * get dev_web_ip attribute * * @return mixed */ public function getDevWebIpAttribute() { $value = Server::find($this->dev_web_server_id); if ($value) { $value = $value->ssh; } return $value; } /** * get dev_db_ip attribute * * @return mixed */ public function getDevDbIpAttribute() { $value = Server::find($this->dev_db_server_id); if ($value) { $value = $value->ssh; } return $value; } /** * get prod_web_ip attribute * * @return mixed */ public function getProdWebIpAttribute() { $value = Server::find($this->prod_web_server_id); if ($value) { $value = $value->ssh; } return $value; } /** * get prod_db_ip attribute * * @return mixed */ public function getProdDbIpAttribute() { $value = Server::find($this->prod_db_server_id); if ($value) { $value = $value->ssh; } return $value; } /** * get checked attribute * * @return mixed */ public function getCheckedAttribute() { $value = ProjectsStatusChecker::select('updated_at')->where('project_uuid', '=', $this->uuid)->first(); if (!$value) { $value = 'missing'; } else { $value = $value->updated_at; $dt = Carbon::now(); if ($dt->diffInMinutes($value) > 30) { $value = 'false'; } else { $value = 'true'; } } return $value; } /** * get sitemap_checked attribute * * @return mixed */ public function getSitemapCheckedAttribute() { $value = ProjectsStatusChecker::select('sitemap')->where('project_uuid', '=', $this->uuid)->first(); if (!$value) { $value = 'missing'; } else { $value = $value->sitemap; } return $value; } /** * get robots_checked attribute * * @return mixed */ public function getRobotsCheckedAttribute() { $value = ProjectsStatusChecker::select('robots')->where('project_uuid', '=', $this->uuid)->first(); if (!$value) { $value = 'missing'; } else { $value = $value->robots; } return $value; } /** * get logs_checked attribute * * @return mixed */ public function getLogsCheckedAttribute() { $value = ProjectsStatusChecker::select('logs')->where('project_uuid', '=', $this->uuid)->first(); if (!$value) { $value = 'missing'; } else { $value = $value->logs; } return $value; } /** * get code attribute * * @return mixed */ public function getCodeAttribute() { $value = ProjectsStatusChecker::select('code')->where('project_uuid', '=', $this->uuid)->first(); if (!$value) { $value = 'missing'; } else { $value = $value->code; } return $value; } /** * get logs_hr attribute * * @return string */ public function getLogsHrAttribute(): string { $value = ProjectsStatusChecker::select('logs')->where('project_uuid', '=', $this->uuid)->first(); return $this->humanFilesize($value->logs); } /** * Human readable file size * * @param float $size * @return string */ private function humanFilesize(float $size): string { $i = \floatval(floor(log($size, 1024))); return round($size / pow(1024, $i), [0,0,2,2,3][$i]) . [' O',' Ko',' Mo',' Go',' To'][$i]; } }