You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To wrap up, create a **migration** to create a new table or alter your existing table to add the timestamp fields:
127
+
Optionally, if your database table hasn't got the datetime columns yet, create a **migration** to create a new table or alter your existing table to add the timestamp fields:
95
128
96
129
```php
97
130
<?php
@@ -107,8 +140,8 @@ return new class extends Migration {
107
140
{
108
141
Schema::table('users', static function (Blueprint $table): void {
All fields should now contain a datetime similar to `2018-05-10 16:24:22`.
138
171
172
+
Note that the date stored in the database column **is immutable, i.e. it's only set once**. Any following updates will not change the stored date(time), unless you update the date column manually or if you set it to `false` and back to `true`.
173
+
174
+
```php
175
+
$user = new User;
176
+
177
+
$user->has_accepted_terms_and_conditions = true;
178
+
$user->save();
179
+
180
+
// `accepted_terms_at` column will contain `2022-03-13 13:20:00`
181
+
182
+
$user->has_accepted_terms_and_conditions = true;
183
+
$user->save();
184
+
185
+
// `accepted_terms_at` column will still contain the original `2022-03-13 13:20:00` date
186
+
```
187
+
139
188
### Clearing saved values
140
189
141
190
Of course you can also remove the saved date and time, for instance if a user retracts their approval:
0 commit comments