Skip to content

Commit cc789f9

Browse files
committed
Date-only doc to Jenssegers MongoDB
1 parent 3ddb3d7 commit cc789f9

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,35 @@ getting as return/setAttribute of the field a string formated using the `to` key
6666
The `approved_at` field in `$dates` array is still handled with the default behavior of the framework.
6767

6868
**Note** that the input value of this fields - `start_date` and `finish_date`, must be in `d/m/Y` format.
69+
70+
### Using Jenssegers/MongoDB
71+
72+
If you are using Jenssegers/MongoDB driver to persist date only, this trait can help you to handle
73+
MongoDB timestamp field type.
74+
75+
To ensure a date gonna be saved in UTC timezone at hour 00:00:00, you must add a `date-only`
76+
setting in array `$mapDateTimeMutator`:
77+
78+
```php
79+
<?php
80+
81+
use Torzer\Common\Traits\MapDateTimeMutator;
82+
83+
class MyClass extends Jenssegers\Mongodb\Eloquent\Model {
84+
85+
use MapDateTimeMutator;
86+
87+
protected $mapDateTimeMutator = [
88+
'start_date' => ['from' => 'd/m/Y', 'to' => 'Y-m-d'],
89+
'finish_date' => ['from' => 'd/m/Y', 'to' => 'Y-m-d'],
90+
'date-only' => true,
91+
];
92+
93+
protected $dates = [
94+
'approved_at', 'start_date', 'finish_date'
95+
];
96+
97+
...
98+
99+
100+
```

0 commit comments

Comments
 (0)