34 lines
994 B
PHP
34 lines
994 B
PHP
<?php
|
|
|
|
namespace App\Tables;
|
|
|
|
use App\Models\Product;
|
|
use App\Tables\Traits\WithExportableProductColumns;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Http\Response;
|
|
use Mmt\GenericTable\Attributes\CellFormatter;
|
|
use Mmt\GenericTable\Components\ColumnCollection;
|
|
use Mmt\GenericTable\Interfaces\IExportable;
|
|
use Mmt\GenericTable\Interfaces\IGenericTable;
|
|
use Mmt\GenericTable\Support\ExportEventArgs;
|
|
use Mmt\GenericTable\Support\ExportSettings;
|
|
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
|
|
|
class TableWithExport implements IGenericTable, IExportable
|
|
{
|
|
use WithExportableProductColumns;
|
|
|
|
public function onExport(ExportEventArgs $args) : BinaryFileResponse|Response
|
|
{
|
|
$args->query->take(5);
|
|
$args->settings->useFormatters = true;
|
|
$args->settings->fileName = 'products';
|
|
return $args->export();
|
|
}
|
|
|
|
#[CellFormatter('price')]
|
|
public function priceFormatter($rowModel)
|
|
{
|
|
return '$'.$rowModel->price;
|
|
}
|
|
} |