From 63586c5b1ad8f01047798414b29722460eb85875 Mon Sep 17 00:00:00 2001 From: EJ Beron Date: Thu, 20 Feb 2025 08:26:18 +0800 Subject: [PATCH 1/2] feat: macroable DataTable base class --- src/Services/DataTable.php | 3 +++ tests/DataTableServiceTest.php | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/Services/DataTable.php b/src/Services/DataTable.php index 3d2170c..9fd471a 100644 --- a/src/Services/DataTable.php +++ b/src/Services/DataTable.php @@ -15,6 +15,7 @@ use Illuminate\Support\Arr; use Illuminate\Support\Collection; use Illuminate\Support\LazyCollection; +use Illuminate\Support\Traits\Macroable; use Maatwebsite\Excel\ExcelServiceProvider; use OpenSpout\Common\Entity\Style\Style; use Rap2hpoutre\FastExcel\FastExcel; @@ -29,6 +30,8 @@ abstract class DataTable implements DataTableButtons { + use Macroable; + /** * DataTables print preview view. * diff --git a/tests/DataTableServiceTest.php b/tests/DataTableServiceTest.php index 6f82807..91b1b66 100644 --- a/tests/DataTableServiceTest.php +++ b/tests/DataTableServiceTest.php @@ -10,6 +10,7 @@ use Yajra\DataTables\Buttons\Tests\DataTables\UsersDataTable; use Yajra\DataTables\Buttons\Tests\Models\User; use Yajra\DataTables\EloquentDataTable; +use Yajra\DataTables\Services\DataTable; class DataTableServiceTest extends TestCase { @@ -80,6 +81,20 @@ public function it_allows_response_callback(): void $this->assertEquals(1, $response->json('recordsFiltered')); } + #[Test] + public function it_is_macroable(): void + { + $dataTable = new class extends DataTable {}; + + $this->assertObjectHasProperty('macros', $dataTable); + $this->assertTrue(method_exists($dataTable, 'macro'), 'Method macro does not exist.'); + $this->assertTrue(method_exists($dataTable, 'mixin'), 'Method mixin does not exist.'); + + DataTable::macro('macroMethod', fn () => 'macro'); + + $this->assertEquals('macro', $dataTable->macroMethod()); + } + protected function setUp(): void { parent::setUp(); From 45ee406b5140d0fe478b8e944039700e7d104576 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Wed, 26 Feb 2025 15:15:28 +0800 Subject: [PATCH 2/2] chore: release v12.1.0 :rocket: --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf6e66f..34c9531 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Laravel DataTables Buttons Plugin CHANGELOG. +## v12.1.0 - 2025-02-26 + +- feat: Macroable DataTable Base Class #193 + ## v12.0.0 - 2025-02-26 - Laravel 12.x support