Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhance the excel export feature of model-grid
- Loading branch information
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace Encore\Admin\Grid\Exporters; | ||
|
||
use Maatwebsite\Excel\Concerns\Exportable; | ||
use Maatwebsite\Excel\Concerns\FromQuery; | ||
use Maatwebsite\Excel\Concerns\WithHeadings; | ||
|
||
abstract class ExcelExporter extends AbstractExporter implements FromQuery, WithHeadings | ||
{ | ||
use Exportable; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $fileName; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $headings = []; | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function headings(): array | ||
{ | ||
return $this->headings; | ||
} | ||
|
||
/** | ||
* @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model | ||
*/ | ||
public function query() | ||
{ | ||
return $this->getQuery(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function export() | ||
{ | ||
$this->download($this->fileName)->prepare(request())->send(); | ||
|
||
exit; | ||
} | ||
} |