owen-it / laravel-auditing

Record the change log from models in Laravel
https://laravel-auditing.com
MIT License
3.03k stars 391 forks source link

Type error: Argument 1 passed to Illuminate\Database\Eloquent\Model::serializeDate() #318

Closed netopvh closed 7 years ago

netopvh commented 7 years ago
Q A
Bug? yes
New Feature? no
Framework Laravel
Framework version 5.5.13
Package version 4.1
PHP version 7.1

Description

Hello guyz,

I have a problem using Audit, he is giving the following message:

ype error: Argument 1 passed to Illuminate\Database\Eloquent\Model::serializeDate() must implement interface DateTimeInterface, null given, called in /var/www/ddd/vendor/owen-it/laravel-auditing/src/Audit.php on line 90

From what I've checked the error is occurring in this method:

public function resolveData()
    {
        // Metadata
        $this->data = [
            'audit_id'         => $this->id,
            'audit_event'      => $this->event,
            'audit_url'        => $this->url,
            'audit_ip_address' => $this->ip_address,
            'audit_user_agent' => $this->user_agent,
            'audit_created_at' => $this->serializeDate($this->created_at),
            'audit_updated_at' => $this->serializeDate($this->updated_at),
            'user_id'          => $this->getAttribute(Config::get('audit.user.foreign_key', 'user_id')),
        ];

        if ($this->user) {
            foreach ($this->user->attributesToArray() as $attribute => $value) {
                $this->data['user_'.$attribute] = $value;
            }
        }

        $this->metadata = array_keys($this->data);

        // Modified Auditable attributes
        foreach ($this->new_values as $key => $value) {
            $this->data['new_'.$key] = $value;
        }

        foreach ($this->old_values as $key => $value) {
            $this->data['old_'.$key] = $value;
        }

        $this->modified = array_diff_key(array_keys($this->data), $this->metadata);

        return $this->data;
    }

can anybody help me?

quetzyg commented 7 years ago

Hi @netopvh,

Did you check the troubleshooting section about that issue?

See the upgrading section on how to solve that.