Skip to content

Carbon Objects don't work with Datatables when using getCreatedAtAttribute #3160

Closed
@sgtcoder

Description

@sgtcoder

Summary of problem or feature request

When overriding the getter for the created_at on the model level, the column will display [object object] rather than the formatted datetime. By default, created_at passes as a Carbon object so it can be used in other areas and by being able to call ->format on it. The only work around I found for this is doing an editColumn and then formatting it from there. It just seems tedious that Datatables doesn't support Carbon objects.

Code snippet of problem

public function getCreatedAtAttribute()
    {
        return now()->parse($this->attributes['created_at'])->setTimezone('America/New_York');
    }

System details

  • Operating System
    AlmaLinux 8.7
  • PHP Version
    8.2
  • Laravel Version
    10
  • Laravel-Datatables Version
    10

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions