laravel-mongodb
laravel-mongodb copied to clipboard
[Feature Request] Dynamic Dates - Defining Dates with Dynamic Field Names
Is your feature request related to a problem?
I have a problem where I'm attempting to add a bunch of dates to user-supplied field-names. As an example, think of them like custom tags with a timestamp attached. So every field within this nested relationship will be a date, as in the below structure:
Blog Post
| -> ID = 1
| -> Tags
| -> Tag Name = Timestamp
| -> Tag Name = Timestamp
| -> ...
At present, I'm not sure if there's a way for me to ensure that the Carbon dates I work with in the logic are able to be inserted as a MongoDB Timestamp, since the only facility for managing dates is the presence of the $date property on the model, which as far as I'm aware, doesn't accept wildcards.
So my insert code requires a manual conversion to the \MongoDb\BSON\UTCDateTime
class.
Given the flexible nature of Mongo with fields able to be added ad-hoc, it stands to reason that the rules that define those fields could be more flexible too.
Describe the solution you'd like
Some way to define wildcards, or regex within the $dates
property, so that I can ensure that any date that matches a particular pattern is added converted to and from the appropriate date classes at the appropriate times.
Describe alternatives you've considered
At the moment, if I want to use these dynamic fields in an insert logic, or in a where logic, I must convert the Carbon/Datetime class to \MongoDb\BSON\UTCDateTime
, so I'm not currently prevented from doing this, but the method feels messy and unintegrated.
Additional context
My use case is specific, but there is more I can think of, especially with accountability with our users about when certain features or systems were added to their account.