#Create record with custom creation date

8 messages · Page 1 of 1 (latest)

mortal veldt
#

Hi there,
I want to set a custom creation timestamp for the resource the moment an user opens the create view, and save it with the record without showing it in the form. I tried with different hooks but could not get it working. Any ideas how I can implement this logic without disabling the timestamp in the model?
Thanks

vale heraldBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

spare mantle
#

Do you need the create time stamp to know when the user presses the create button, as opposed to when the record is actually written to row?

mortal veldt
#

Yes I would like to "abuse" the create timestamp to keep track of the button click instead of when the record is written to the db

spare mantle
#

You could just have a hidden field that will timestamp the form creation time:

                                ->hidden()
                                ->default(now()),```

Then use that field $data to inform the database. 

I'd be cautious of interfering with `created_at`, I'd have an alternative field.
mortal veldt
#

Thank @spare mantle ! Any specific reasons for your concerns about using the default field?

spare mantle
#

Laravel automates a lot of timestamp stuff for you. I can't think of anything off the top of my head...but maybe someone doing something somewhere that relies on an incremental ID field and created_at to match...

I would have to have a very good reason, and no real alternative to manually set a field which 99% of the time, we never touch.

mortal veldt
#

Thank you for sharing, then I will add a custom field to track the process start, it's just adding more complexity, so I thought it would be more aligned if I use the default timestamp column.