File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -121,6 +121,26 @@ public function it_can_return_formatted_columns()
121
121
$ this ->assertEquals (Carbon::parse ($ user ->created_at )->format ('Y-m-d ' ), $ data ['created_at_formatted ' ]);
122
122
}
123
123
124
+ /** @test */
125
+ public function it_can_return_formatted_column_using_closure ()
126
+ {
127
+ $ crawler = $ this ->call ('GET ' , '/eloquent/formatColumn-closure ' );
128
+
129
+ $ crawler ->assertJson ([
130
+ 'draw ' => 0 ,
131
+ 'recordsTotal ' => 20 ,
132
+ 'recordsFiltered ' => 20 ,
133
+ ]);
134
+
135
+ $ user = User::find (1 );
136
+ $ data = $ crawler ->json ('data ' )[0 ];
137
+
138
+ $ this ->assertTrue (isset ($ data ['created_at ' ]));
139
+ $ this ->assertTrue (isset ($ data ['created_at_formatted ' ]));
140
+
141
+ $ this ->assertEquals (Carbon::parse ($ user ->created_at )->format ('Y-m-d ' ), $ data ['created_at_formatted ' ]);
142
+ }
143
+
124
144
/** @test */
125
145
public function it_accepts_a_relation ()
126
146
{
@@ -152,5 +172,10 @@ protected function setUp(): void
152
172
->formatColumn ('created_at ' , new DateFormatter ('Y-m-d ' ))
153
173
->toJson ();
154
174
});
175
+ $ router ->get ('/eloquent/formatColumn-closure ' , function (DataTables $ dataTable ) {
176
+ return $ dataTable ->eloquent (User::query ())
177
+ ->formatColumn ('created_at ' , fn ($ value , $ row ) => Carbon::parse ($ value )->format ('Y-m-d ' ))
178
+ ->toJson ();
179
+ });
155
180
}
156
181
}
You can’t perform that action at this time.
0 commit comments