Skip to content

Commit 6204b30

Browse files
authored
Fix compatibility with PHP7.4 and DataTables v9 (#24)
1 parent cd19015 commit 6204b30

File tree

4 files changed

+20
-19
lines changed

4 files changed

+20
-19
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
strategy:
1515
fail-fast: true
1616
matrix:
17-
php: [8.0, 8.1]
17+
php: [7.4, 8.0, 8.1]
1818
stability: [prefer-stable]
1919

2020
name: PHP ${{ matrix.php }} - ${{ matrix.stability }}

composer.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
},
2626
"require-dev": {
2727
"maatwebsite/excel": "^3.1.40",
28-
"nunomaduro/larastan": "^2.1",
29-
"orchestra/testbench": "^7.3"
28+
"nunomaduro/larastan": "^1.0|^2.1",
29+
"orchestra/testbench": "6.*|^7.3"
3030
},
3131
"autoload": {
3232
"psr-4": {
@@ -41,10 +41,7 @@
4141
"config": {
4242
"preferred-install": "dist",
4343
"sort-packages": true,
44-
"optimize-autoloader": true,
45-
"platform": {
46-
"php": "8.0.2"
47-
}
44+
"optimize-autoloader": true
4845
},
4946
"extra": {
5047
"branch-alias": {

src/Jobs/DataTableExportJob.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,24 @@ class DataTableExportJob implements ShouldQueue, ShouldBeUnique
4040

4141
public array $request;
4242

43-
public int $user;
43+
/**
44+
* @var int|string
45+
*/
46+
public $user;
4447

4548
/**
4649
* Create a new job instance.
4750
*
4851
* @param array $dataTable
4952
* @param array $request
50-
* @param ?int $user
53+
* @param int|string $user
5154
*/
52-
public function __construct(array $dataTable, array $request, ?int $user)
55+
public function __construct(array $dataTable, array $request, $user)
5356
{
5457
$this->dataTable = $dataTable[0];
5558
$this->attributes = $dataTable[1];
5659
$this->request = $request;
57-
$this->user = $user ?? 0;
60+
$this->user = $user;
5861
}
5962

6063
/**

src/WithExportQueue.php

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

33
namespace Yajra\DataTables;
44

5+
use Illuminate\Support\Facades\Auth;
56
use Illuminate\Support\Facades\Bus;
67
use Yajra\DataTables\Jobs\DataTableExportJob;
78

@@ -20,7 +21,7 @@ trait WithExportQueue
2021
*
2122
* @throws \Throwable
2223
*/
23-
public function render(string $view, array $data = [], array $mergeData = [])
24+
public function render($view, $data = [], $mergeData = [])
2425
{
2526
if (request()->ajax() && request('action') == 'exportQueue') {
2627
return $this->exportQueue();
@@ -38,13 +39,13 @@ public function render(string $view, array $data = [], array $mergeData = [])
3839
*/
3940
public function exportQueue(): string
4041
{
41-
$batch = Bus::batch([
42-
new DataTableExportJob(
43-
[self::class, $this->attributes],
44-
$this->request->all(),
45-
optional($this->request->user())->id
46-
),
47-
])->name('datatables-export')->dispatch();
42+
$job = new DataTableExportJob(
43+
[self::class, $this->attributes],
44+
request()->all(),
45+
Auth::id() ?? 0
46+
);
47+
48+
$batch = Bus::batch([$job])->name('datatables-export')->dispatch();
4849

4950
return $batch->id;
5051
}

0 commit comments

Comments
 (0)