Skip to content

Commit 26cb4da

Browse files
author
rtrenuela
committed
Add export purge with command
1 parent 62634db commit 26cb4da

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace Yajra\DataTables\Commands;
4+
5+
use Illuminate\Console\Command;
6+
use Illuminate\Support\Facades\Storage;
7+
8+
class DataTablesPurgeExportCommand extends Command
9+
{
10+
/**
11+
* The name and signature of the console command.
12+
*
13+
* @var string
14+
*/
15+
protected $signature = 'datatables:purge-export';
16+
17+
/**
18+
* The console command description.
19+
*
20+
* @var string
21+
*/
22+
protected $description = 'Remove exported files that datatables-export generate.';
23+
24+
/**
25+
* Create a new command instance.
26+
*
27+
* @return void
28+
*/
29+
public function __construct()
30+
{
31+
parent::__construct();
32+
}
33+
34+
/**
35+
* Execute the console command.
36+
*
37+
* @return void
38+
*/
39+
public function handle()
40+
{
41+
collect(Storage::listContents('exports'))
42+
->each(function ($file) {
43+
Storage::delete($file['path']);
44+
});
45+
46+
$this->info('The command was successful. Export files are cleared!');
47+
}
48+
}

src/ExportServiceProvider.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Support\ServiceProvider;
66
use Livewire\Livewire;
77
use Maatwebsite\Excel\ExcelServiceProvider;
8+
use Yajra\DataTables\Commands\DataTablesPurgeExportCommand;
89
use Yajra\DataTables\Generators\DataTablesHtmlCommand;
910
use Yajra\DataTables\Generators\DataTablesMakeCommand;
1011
use Yajra\DataTables\Generators\DataTablesScopeCommand;
@@ -48,5 +49,11 @@ protected function publishAssets()
4849
public function register()
4950
{
5051
$this->mergeConfigFrom(__DIR__ . '/config/datatables-export.php', 'datatables-export');
52+
53+
$this->commands(
54+
[
55+
DataTablesPurgeExportCommand::class,
56+
]
57+
);
5158
}
5259
}

0 commit comments

Comments
 (0)