File tree Expand file tree Collapse file tree 2 files changed +53
-0
lines changed
Expand file tree Collapse file tree 2 files changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -163,6 +163,29 @@ public function encrypted_casts_work_with_virtual_column() {
163163 // Reset static property
164164 MyModel::$ customEncryptedCastables = [];
165165 }
166+
167+ #[Test]
168+ public function updating_model_does_not_store_timestamps_in_the_virtual_column () {
169+ /** @var TimestampModel $model */
170+ $ model = TimestampModel::create ();
171+ $ dbRecordDataColumn = fn () => DB ::selectOne ('select * from timestamp_models where id = ? ' , [$ model ->id ])->data ;
172+
173+ $ this ->assertStringNotContainsString ('created_at ' , $ dbRecordDataColumn ());
174+ $ this ->assertStringNotContainsString ('updated_at ' , $ dbRecordDataColumn ());
175+
176+ $ model ->update (['data ' => ['virtual ' => 'bar ' ]]);
177+
178+ $ this ->assertStringNotContainsString ('created_at ' , $ dbRecordDataColumn ());
179+ $ this ->assertStringNotContainsString ('updated_at ' , $ dbRecordDataColumn ());
180+ }
181+ }
182+
183+ class TimestampModel extends Model
184+ {
185+ use VirtualColumn;
186+
187+ public $ timestamps = true ;
188+ protected $ guarded = [];
166189}
167190
168191class ParentModel extends Model
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ use Illuminate \Database \Migrations \Migration ;
6+ use Illuminate \Database \Schema \Blueprint ;
7+ use Illuminate \Support \Facades \Schema ;
8+
9+ class CreateTimestampModelsTable extends Migration
10+ {
11+ /**
12+ * Run the migrations.
13+ *
14+ * @return void
15+ */
16+ public function up ()
17+ {
18+ Schema::create ('timestamp_models ' , function (Blueprint $ table ) {
19+ $ table ->increments ('id ' );
20+
21+ $ table ->timestamps ();
22+ $ table ->json ('data ' );
23+ });
24+ }
25+
26+ public function down ()
27+ {
28+ Schema::dropIfExists ('timestamp_models ' );
29+ }
30+ }
You can’t perform that action at this time.
0 commit comments