You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

39 lines
965 B

<?php
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Serverlog extends Model
{
use HasFactory;
protected $table = 'serverlog';
protected $fillable = [
'to_ip',
'to_time',
'this_ip',
'this_time',
'diffsecond',
'name',
];
protected $appends = ['before_time', 'timeout'];
public function getBeforeTimeAttribute()
{
return substr(Carbon::parse($this->this_time)->subMilliseconds($this->diffsecond)->format('Y-m-d H:i:s.u'), 0, -3);
}
public function getTimeoutAttribute()
{
// this_time 與現在差超過150秒則回傳1 代表超時
return Carbon::parse($this->this_time)->diffInSeconds() > 150 ? 1 : 0;
}
// 修改現有的diffsecond格式
public function getDiffsecondAttribute($value)
{
return floatval($value) * 1000;
}
}