Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning explode(): Passing null to parameter #2 when using only created_at on model timestamps #832

Closed
leandrodiogenes opened this issue May 20, 2023 · 0 comments · Fixed by #833

Comments

@leandrodiogenes
Copy link

leandrodiogenes commented May 20, 2023

Q A
Bug? yes
New Feature? no
Framework Laravel
Framework version 9.52.2
Package version 13.5
PHP version 8.1.3

Actual Behaviour

I have a model that has the created_at column but doesn't have the updated_at column.

To continue using laravel timestamp only in created_at I set the constant UPDATED_AT to null in the model.

...
class MyModel extends Model implements \OwenIt\Auditing\Contracts\Auditable {

    use \OwenIt\Auditing\Auditable;

    const CREATED_AT = 'created_at';
    const UPDATED_AT = null;
...
}

The problem is when I add the auditable to the model with timestamps=true in the auditable's config.

...
    /*
    |--------------------------------------------------------------------------
    | Audit Timestamps
    |--------------------------------------------------------------------------
    |
    | Should the created_at, updated_at and deleted_at timestamps be audited?
    |
    */

    'timestamps' => false,

im receiving an warning like that

<warning> DEPRECATED </warning> explode(): Passing null to parameter #2 ($string) of type string is deprecated in vendor\laravel\framework\src\Illuminate\Collections\Arr.php on line 281.

I found the problem here...

$attributes = Arr::except($this->attributes, $this->excludedAttributes);

The value of $this->excludedAttributes is:

[ 'created_at', 'null']

Expected Behaviour

An execution without any warning

Steps to Reproduce

Already mentioned

Possible Solutions

Filter the array of excluded attributes to avoid null values;

$attributes = Arr::except($this->attributes, array_filter($this->excludedAttributes));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant