fiament 导出excel,怎么在浏览器中导出而不是在本地laravel代码storage/app/public导出
1. 运行环境
mac m2
PHP:8.3.11
laravel:10.48.20
filament:3.2
2. 问题描述?
根据官方文档步骤导出excel
Export action - Actions - Filament (laravel-filament.cn)
php artisan queue:batches-table
php artisan notifications:table
php artisan vendor:publish --tag=filament-actions-migrations
php artisan migrate
php artisan make:filament-exporter Product --generate
这是资源控制器代码
如果报错:
Method Filament\Actions\ExportAction::table does not exist.
在导出excel的时候要这样写
\Filament\Tables\Actions\ExportAction::make()
参考链接:github.com/filamentphp/filament/di...
<?php
namespace App\Filament\Resources;
use App\Filament\Resources\PatientResource\Pages;
use App\Filament\Resources\PatientResource\RelationManagers;
use App\Models\Patient;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Filament\Forms\Components\TextInput;
use Filament\Tables\Actions\CreateAction;
use App\Filament\Exports\PatientExporter;
class PatientResource extends Resource
{
protected static ?string $model = Patient::class;
protected static ?string $navigationLabel = '病人管理';
// 设置列表页面的标题
protected static ?string $modelLabel = '病人管理';
// 设置列表页面中单个条目的名称
// protected static ?string $modelSingularLabel = '文章';
// 设置列表页面中多个条目的名称
// protected static ?string $modelPluralLabel = '文章管理';
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('name')
->required()
->maxLength(255),
Forms\Components\Select::make('type')
->options([
'cat' => 'Cat',
'dog' => 'Dog',
'rabbit' => 'Rabbit',
])
->required(),
Forms\Components\DatePicker::make('date_of_birth')
->required()
->maxDate(now()),
Forms\Components\Select::make('owner_id')
->relationship('owner', 'name')
->searchable()
->preload()
->createOptionForm([
Forms\Components\TextInput::make('name')
->required()
->maxLength(255),
Forms\Components\TextInput::make('email')
->label('Email address')
->email()
->required()
->maxLength(255),
Forms\Components\TextInput::make('phone')
->label('Phone number')
->tel()
->required(),
])
->required()
]);
}
public static function table(Table $table): Table
{
return $table
->headerActions([
CreateAction::make()
->form([
TextInput::make('name')
->required()
->maxLength(255),
// ...
]),
\Filament\Tables\Actions\ExportAction::make()
->exporter(PatientExporter::class)
// ->fileDisk(null)
// ->fileDisk('public')
->formats([
ExportFormat::Csv,
])
->fileName(fn (Export $export): string => "patient-{$export->getKey()}.csv"),
])
->columns([
Tables\Columns\TextColumn::make('name')
->searchable(),
Tables\Columns\TextColumn::make('type'),
Tables\Columns\TextColumn::make('date_of_birth')
->sortable(),
Tables\Columns\TextColumn::make('owner.name')
->searchable(),
])
->filters([
//
Tables\Filters\SelectFilter::make('type')
->options([
'cat' => 'Cat',
'dog' => 'Dog',
'rabbit' => 'Rabbit',
]),
])
->actions([
Tables\Actions\EditAction::make(),
// CreateAction::make()
// ->model(Patient::class)
// ->form([
// TextInput::make('name')
// ->required()
// ->maxLength(255),
// // ...
// ]),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}
public static function getRelations(): array
{
return [
//
RelationManagers\TreatmentsRelationManager::class,
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListPatients::route('/'),
'create' => Pages\CreatePatient::route('/create'),
'edit' => Pages\EditPatient::route('/{record}/edit'),
];
}
// protected function getHeaderActions(): array
// {
// return [
// ExportAction::make()->exports([
// ExcelExport::make('patient')->fromTable(),
// ])
// ];
// }
}
开始导出
啥也没有,浏览器没有反应,导出个寂寞
3. 您期望得到的结果?
求各位大佬不吝赐教
推荐文章: