Skip to content

Commit 29cb387

Browse files
authored
Merge pull request #100 from ejgandelaberon/editor-as-route-action
feat: Editor as route action
2 parents cba82a8 + 1c8c279 commit 29cb387

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/DataTablesEditor.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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
*/

tests/Feature/DataTablesEditorTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Yajra\DataTables\Tests\Feature;
44

5+
use Illuminate\Routing\Router;
56
use PHPUnit\Framework\Attributes\Test;
67
use Yajra\DataTables\DataTablesEditorException;
78
use 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
}

0 commit comments

Comments
 (0)