'date:Y-m-d']; protected $fillable = [ 'ip_pool_id', 'ip_address', 'action', 'effective_date', 'status_from', 'status_to', 'customer_id', 'customer_name', 'service_name', 'service_id', 'vm_name', 'email_to', 'user_id', 'note', ]; public static function record(IpPool $pool, string $action, string $statusFrom, array $attributes = []): self { return self::create([ 'ip_pool_id' => $pool->id, 'ip_address' => $pool->ip_address, 'action' => $action, 'status_from' => $statusFrom, 'status_to' => $pool->status, 'user_id' => auth('admin')->id(), ...$attributes, ]); } public static function recordVm(?int $poolId, string $action, string $statusFrom, ModuleVmware $vm, ?string $note = null): void { $pool = $poolId ? IpPool::find($poolId) : null; if (!$pool) { return; } $service = Service::where('id', $vm->service_id)->orWhere('vm_id', $vm->id)->first(['id', 'server_name']); self::record($pool, $action, $statusFrom, [ 'vm_name' => $vm->name, 'service_id' => $service?->id, 'service_name' => $service?->server_name, 'customer_id' => $vm->customer_id, 'customer_name' => Customer::whereKey($vm->customer_id)->value('fullname'), 'note' => $note, ]); } public function user(): BelongsTo { return $this->belongsTo(User::class); } }