Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/DataTablesEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ abstract class DataTablesEditor
*/
protected array $currentData = [];

public function __invoke(): JsonResponse
{
return $this->process();
}

/**
* Process dataTables editor action request.
*/
Expand Down
22 changes: 22 additions & 0 deletions tests/Feature/DataTablesEditorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Yajra\DataTables\Tests\Feature;

use Illuminate\Routing\Router;
use PHPUnit\Framework\Attributes\Test;
use Yajra\DataTables\DataTablesEditorException;
use Yajra\DataTables\Tests\Editors\UsersDataTableEditor;
Expand Down Expand Up @@ -38,4 +39,25 @@ public function it_can_set_model_instance_via_runtime()
$editor->setModel(new Post);
$this->assertEquals(new Post, $editor->getModel());
}

#[Test]
public function it_can_be_used_as_route_action(): void
{
/** @var Router $router */
$router = $this->app['router'];
$router->post('editor-as-route-action', UsersDataTableEditor::class);

$this->postJson('editor-as-route-action', [
'action' => 'create',
'data' => [
[
'name' => 'New User',
'email' => 'newuser@email.test',
],
],
])
->assertOk()
->assertJsonStructure(['action', 'data'])
->assertJsonPath('action', 'create');
}
}
Loading