Skip to content

timestamps are mistakenly created for customized timestamps #305

Description

@boxsnake

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions