Laravel-mongodb: Save a date in a nested array

Created on 27 Aug 2014  路  2Comments  路  Source: jenssegers/laravel-mongodb

I want to save a date, in the Mongo date format, in a nested array. I know how to do this with first level attributes, by using Eloquent date mutator, but I have no idea if it's possible with nested attributes.

The data structure looks like that :

things: [
    {
        id: "53fe00511bbed96e0a0041a9",
        date: "2014-08-27 17:59:13",
        ...
    }
]

This is not an embedded relationship. This is more a kind of many to many relationship with pivot data.

I have tried to save a string and an instance of Carbon as a date but they are saved, respectively, as a string and an array and the getter return a string and an array.

Most helpful comment

I currently have to use mutator functions to accomplish something like this. The model has a couple of methods that make life easier to do this however

$this->asDateTime(string)
and
$this->fromDateTime(string)

+1 for being able to specify nested properties as dates like root level date properties can be.

All 2 comments

I currently have to use mutator functions to accomplish something like this. The model has a couple of methods that make life easier to do this however

$this->asDateTime(string)
and
$this->fromDateTime(string)

+1 for being able to specify nested properties as dates like root level date properties can be.

could you specify i have the same problem

Was this page helpful?
0 / 5 - 0 ratings

Related issues

naveedyasin picture naveedyasin  路  3Comments

geofflancaster picture geofflancaster  路  3Comments

sanjay1688 picture sanjay1688  路  3Comments

viacheslavpleshkov picture viacheslavpleshkov  路  3Comments

yupangestu picture yupangestu  路  3Comments