File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ public static function fromModel(Model $model)
2222 {
2323 return (new static ())
2424 ->id ($ model ->id )
25- ->date ($ model ->data [ ' date ' ] ?? Carbon::now ())
25+ ->date ($ model ->created_at ?? Carbon::now ())
2626 ->data (Arr::except ($ model ->data , 'date ' ))
2727 ->model ($ model );
2828 }
Original file line number Diff line number Diff line change 66use PHPUnit \Framework \Attributes \Test ;
77use Statamic \Eloquent \Forms \FormModel ;
88use Statamic \Eloquent \Forms \SubmissionModel ;
9+ use Statamic \Facades ;
910use Tests \TestCase ;
1011
1112class FormSubmissionTest extends TestCase
@@ -81,4 +82,23 @@ public function it_should_not_overwrite_submissions()
8182
8283 $ this ->assertCount (2 , SubmissionModel::all ());
8384 }
85+
86+ #[Test]
87+ public function it_should_not_save_date_in_data ()
88+ {
89+ $ form = tap (Facades \Form::make ('test ' )->title ('Test ' ))
90+ ->save ();
91+
92+ $ submission = tap ($ form ->makeSubmission ([
93+ 'name ' => 'John Doe ' ,
94+ ]))->save ();
95+
96+ $ this ->assertInstanceOf (Carbon::class, $ submission ->date ());
97+ $ this ->assertArrayNotHasKey ('date ' , $ submission ->model ()->data );
98+
99+ $ fresh = \Statamic \Eloquent \Forms \Submission::fromModel ($ submission ->model ()->fresh ());
100+
101+ $ this ->assertInstanceOf (Carbon::class, $ fresh ->date ());
102+ $ this ->assertSame ($ fresh ->date ()->format ('u ' ), $ submission ->date ()->format ('u ' ));
103+ }
84104}
You can’t perform that action at this time.
0 commit comments