Coder Social home page Coder Social logo

Comments (2)

RemiCollin avatar RemiCollin commented on June 19, 2024

You're right as in the update process, the timestamps attributes are set with Carbon::now() which the Illuminate Query translate into the correct datetime format, but the inverse is not true, as date attribute is hydrated as a string, which leads to this inconsistency.

Several ways to solve this :

  1. Cast the carbon object to string after the update/create query.
  2. Hydrate date attributes with instance of Carbon.
  3. Add a $dates attribute to the entity map to customize this behaviour. If the attribute is contained in the array, it will be hydrated with an instance of Carbon, if it's not with a string. Of course this raises the question of which behaviour to choose as a default for the timestamps. I'd tend to go on the Carbon side, but i'd like to make some benchmarks to see if it's not too costy in terms of hydration performance.

That's for the big picture.

Concerning the toArray() method, I think we can simply test if the attribute is an instance of carbon, and casting it to string if it's so. This will work whatever option we choose for the hydration behaviour. Feel free to PR it ;)

from analogue.

RemiCollin avatar RemiCollin commented on June 19, 2024

Fixed the casting in v2.1.7 release

from analogue.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.