File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -96,6 +96,11 @@ abstract class DataTablesEditor
9696 */
9797 protected array $ currentData = [];
9898
99+ public function __invoke (): JsonResponse
100+ {
101+ return $ this ->process ();
102+ }
103+
99104 /**
100105 * Process dataTables editor action request.
101106 */
Original file line number Diff line number Diff line change 22
33namespace Yajra \DataTables \Tests \Feature ;
44
5+ use Illuminate \Routing \Router ;
56use PHPUnit \Framework \Attributes \Test ;
67use Yajra \DataTables \DataTablesEditorException ;
78use Yajra \DataTables \Tests \Editors \UsersDataTableEditor ;
@@ -38,4 +39,25 @@ public function it_can_set_model_instance_via_runtime()
3839 $ editor ->setModel (new Post );
3940 $ this ->assertEquals (new Post , $ editor ->getModel ());
4041 }
42+
43+ #[Test]
44+ public function it_can_be_used_as_route_action (): void
45+ {
46+ /** @var Router $router */
47+ $ router = $ this ->app ['router ' ];
48+ $ router ->post ('editor-as-route-action ' , UsersDataTableEditor::class);
49+
50+ $ this ->postJson ('editor-as-route-action ' , [
51+ 'action ' => 'create ' ,
52+ 'data ' => [
53+ [
54+ 'name ' => 'New User ' ,
55+ 'email ' => 'newuser@email.test ' ,
56+ ],
57+ ],
58+ ])
59+ ->assertOk ()
60+ ->assertJsonStructure (['action ' , 'data ' ])
61+ ->assertJsonPath ('action ' , 'create ' );
62+ }
4163}
You can’t perform that action at this time.
0 commit comments