File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed
Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -157,6 +157,28 @@ public function testEncryptedCastsWorkWithVirtualColumn() {
157157 // Reset static property
158158 MyModel::$ customEncryptedCastables = [];
159159 }
160+
161+ public function testUpdatingModelDoesNotStoreTimestampsInTheVirtualColumn () {
162+ /** @var TimestampModel $model */
163+ $ model = TimestampModel::create ();
164+ $ dbRecordDataColumn = fn () => DB ::selectOne ('select * from timestamp_models where id = ? ' , [$ model ->id ])->data ;
165+
166+ $ this ->assertStringNotContainsString ('created_at ' , $ dbRecordDataColumn ());
167+ $ this ->assertStringNotContainsString ('updated_at ' , $ dbRecordDataColumn ());
168+
169+ $ model ->update (['data ' => ['virtual ' => 'bar ' ]]);
170+
171+ $ this ->assertStringNotContainsString ('created_at ' , $ dbRecordDataColumn ());
172+ $ this ->assertStringNotContainsString ('updated_at ' , $ dbRecordDataColumn ());
173+ }
174+ }
175+
176+ class TimestampModel extends Model
177+ {
178+ use VirtualColumn;
179+
180+ public $ timestamps = true ;
181+ protected $ guarded = [];
160182}
161183
162184class 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