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

timestamps are mistakenly created for customized timestamps #305

Open
boxsnake opened this issue Dec 3, 2024 · 0 comments
Open

timestamps are mistakenly created for customized timestamps #305

boxsnake opened this issue Dec 3, 2024 · 0 comments

Comments

@boxsnake
Copy link

boxsnake commented Dec 3, 2024

A simplified models.php config is as following:

  • With timestamp enabled with customized fields
  • With property constants generation
  • With base files generation
  • With $hidden & $fillable in base files
<?php
return [
    '*' => [
        ...
        'timestamps' => [
            'enabled' => true,
            'fields' => [
                'CREATED_AT' => 'create_time',
                'UPDATED_AT' => 'update_time',
            ]
        ],
        'base_files' => true,
        'with_property_constants' => true,
        'hidden_in_base_files' => true,
        'fillable_in_base_files' => true,
    ],
];

The generated base models have the following consts and casts:

const CREATED_AT = 'create_time';
const UPDATED_AT = 'update_time';
...

protected $casts = [
  ...
  self::CREATE_TIME => 'int',
  self::UPDATE_TIME => 'int',
  ...
];

Property's CREATED_AT AND UPDATED_AT are right, since Eloquent's HasTimestamps traits ( \Illuminate\Database\Eloquent\Concerns\HasTimestamps) uses these two constants.

However, the generated $casts are with the wrong keys. The self::CREATE_TIME and self::UPDATE_TIME keys should be self::CREATED_AT and self::UPDATED_AT.

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

No branches or pull requests

1 participant