Skip to content

Commit b9e60cd

Browse files
authored
Merge pull request #10 from throwexceptions/master
Enhancement: Passing attributes with self::class
2 parents 0a17382 + 34e8a2b commit b9e60cd

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

src/Jobs/DataTableExportJob.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,28 @@
1616

1717
class DataTableExportJob implements ShouldQueue, ShouldBeUnique
1818
{
19-
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
19+
use Dispatchable;
20+
use InteractsWithQueue;
21+
use Queueable;
22+
use SerializesModels;
2023
use Batchable;
2124

2225
private string $dataTable;
26+
private array $attributes;
2327
private array $request;
2428
private $user;
2529

2630
/**
2731
* Create a new job instance.
2832
*
29-
* @return void
33+
* @param array $dataTable
34+
* @param array $request
35+
* @param null $user
3036
*/
31-
public function __construct(string $dataTable, array $request, $user = null)
37+
public function __construct(array $dataTable, array $request, $user = null)
3238
{
33-
$this->dataTable = $dataTable;
39+
$this->dataTable = $dataTable[0];
40+
$this->attributes = $dataTable[1];
3441
$this->request = $request;
3542
$this->user = $user;
3643
}
@@ -50,7 +57,7 @@ public function handle()
5057
$oTable = resolve($this->dataTable);
5158
request()->merge($this->request);
5259

53-
$query = app()->call([$oTable, 'query']);
60+
$query = app()->call([$oTable->with($this->attributes), 'query']);
5461

5562
/** @var \Yajra\DataTables\QueryDataTable $dataTable */
5663
$dataTable = app()->call([$oTable, 'dataTable'], compact('query'));

src/WithExportQueue.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ trait WithExportQueue
1515
* @param array $mergeData
1616
* @return mixed
1717
*/
18-
public function render($view, $data = [], $mergeData = [])
18+
public function render(string $view, array $data = [], array $mergeData = [])
1919
{
2020
if (! $this->request()->wantsJson() && $this->request()->get('action') == 'exportQueue') {
2121
return $this->exportQueue();
@@ -25,12 +25,18 @@ public function render($view, $data = [], $mergeData = [])
2525
}
2626

2727
/**
28+
* Create and run batch job.
29+
*
2830
* @throws \Throwable
2931
*/
3032
public function exportQueue(): string
3133
{
3234
$batch = Bus::batch([
33-
new DataTableExportJob(self::class, $this->request->all(), optional($this->request->user())->id),
35+
new DataTableExportJob(
36+
[self::class, $this->attributes],
37+
$this->request->all(),
38+
optional($this->request->user())->id
39+
),
3440
])->name('datatables-export')->dispatch();
3541

3642
return $batch->id;

0 commit comments

Comments
 (0)