lucassdoro / filament-sheetpilot
Excel and CSV import action for Filament, compatible with the eightynine/filament-excel-import API.
Requires
- php: ^8.2
- filament/filament: ^4.13|^5.0
- illuminate/contracts: ^11.28|^12.0|^13.0
- maatwebsite/excel: ^3.1.68
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.18
- orchestra/testbench: ^9.0|^10.0|^11.0
- pestphp/pest: ^3.0|^4.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Excel and CSV import action for Filament 4 and 5.
SheetPilot adds an import button to any Filament resource or relation manager. Users upload a spreadsheet, the rows can be validated before anything is saved, and each row becomes a record. It keeps the public API of eightynine/filament-excel-import, so moving an existing panel over is mostly a namespace change.
Features
- Import
.xlsx,.xlsand.csvfiles from a resource page or a relation manager, includingBelongsToManypivot columns. - Validate the whole file before anything is saved, with errors grouped by message and spreadsheet row.
- Stop an import from your own class with an error, warning, info or success message.
- Offer a sample spreadsheet built from an array or hosted elsewhere.
- Change every label and notification with Filament's own action methods or the translation files.
- Optional create authorization, database transactions on any connection, and deleting the upload after the import.
- Translations for English, Brazilian Portuguese, Simplified Chinese and Traditional Chinese.
Requirements
- PHP 8.2 or higher (8.3 for Laravel 13)
- Laravel 11, 12 or 13
- Filament 4.13 or higher, or Filament 5
- Laravel Excel 3.1, installed with the package
Installation
composer require lucassdoro/filament-sheetpilot
There is no install command and no migration. Publishing the config and the translations is optional:
php artisan vendor:publish --tag=sheetpilot-config php artisan vendor:publish --tag=sheetpilot-translations
Quick start
Security: the default import saves each row with
Model::create(), using the spreadsheet headers as attributes. A model with$guarded = []accepts any column the file brings. Use$fillableorvalidateUsing()to control what gets saved. See Security.
Add the action to the header of a resource's list page:
use LucasDoro\SheetPilot\ExcelImportAction; protected function getHeaderActions(): array { return [ ExcelImportAction::make() ->validateUsing([ 'name' => 'required', 'email' => 'required|email', ]), ]; }
The first row of the spreadsheet is the header. Each header becomes an attribute in snake case, so E-mail Address turns into e_mail_address.
Use your own import class when the rows need more than Model::create():
ExcelImportAction::make() ->use(ContactsImport::class);
Contents
- Migrating from eightynine/filament-excel-import
- Usage
- Configuration
- Optional behavior
- Errors and transactions
- API reference
- Testing
- Compatibility
- Known limits
- Security
- Contributing
Migrating from eightynine/filament-excel-import
-
Install SheetPilot next to the old package:
composer require lucassdoro/filament-sheetpilot
-
Replace the namespace and the translation keys in your code:
Before After EightyNine\ExcelImport\LucasDoro\SheetPilot\excel-import::excel-import.sheetpilot::sheetpilot.config('excel-import.config('sheetpilot.// Before use EightyNine\ExcelImport\ExcelImportAction; // After use LucasDoro\SheetPilot\ExcelImportAction;
-
If you published the old config, publish the new one and copy
upload_diskover:php artisan vendor:publish --tag=sheetpilot-config
Until you do, SheetPilot keeps reading
excel-import.upload_diskand logs a warning. -
Move published translations from
lang/vendor/excel-import/<locale>/excel-import.phptolang/vendor/sheetpilot/<locale>/sheetpilot.php. -
Delete published stubs in
stubs/filament-excel-import/. -
Remove uses of
EightyNine\ExcelImport\Facades\ExcelImportActionandEightyNine\ExcelImport\Testing\TestsExcelImportAction. They did nothing in the original package and have no replacement. See Testing for a test that covers the action. -
Remove the old package:
composer remove eightynine/filament-excel-import
Both packages register a panel plugin with the id filament-excel-import, so filament('filament-excel-import') keeps working. Do not register both plugins on the same panel.
There is no filament-excel-import:install equivalent. SheetPilot has no migration and needs no install step. To create import classes, use php artisan make:import from Laravel Excel.
What is the same and what changed
| Method | Notes |
|---|---|
use, validateUsing, mutateBeforeValidationUsing, mutateAfterValidationUsing, processCollectionUsing |
Same |
beforeImport, afterImport, additionalData, customImportData |
Same |
beforeUploadField, afterUploadField, uploadField, acceptedFileTypes, storeFiles, visibility |
Same |
disk |
Same. Without it, the disk comes from sheetpilot.upload_disk, then excel-import.upload_disk, then the default disk |
sampleExcel, sampleFileExcel, setSampleData, setSampleFileName, setSampleButtonLabel, setDefaultExportClass, downloadSampleExcelFile, setActionCustomisationClosure |
Same |
action |
Only accepts 'importData', as before. Other values throw InvalidArgumentException |
authorizeCreate, deleteUploadedFile, useTransaction, uploadFieldLabel, stoppedNotification |
New, opt-in |
successNotification, successNotificationTitle, failureNotification, failureNotificationTitle, failureNotificationBody |
Filament's own methods, now applied to the import notifications |
| Upload field label | Spreadsheet instead of {Model plural} Excel Data |
| Validation message | Says that no rows were saved and lists each error once with up to 5 rows |
| Blank rows | Skipped instead of saved or validated |
| File types | Only .xlsx, .xls and .csv, read with the matching reader |
| Success notification | Says how many rows were imported, and warns when the file had none |
| Database error during the default import | Shows a notification instead of an error page |
load_stylesheet config |
Removed. SheetPilot ships no CSS |
DefaultImport, EnhancedDefaultImport, DefaultRelationshipImport, EnhancedDefaultRelationshipImport, ValidationImport, SampleExcelExport, ImportStoppedException, ExcelImportPlugin, Tables\ExcelImportRelationshipAction and the Concerns\* traits keep their names and public methods.
Usage
Validation
The whole file is validated before anything is saved. If a row fails, nothing is imported and the upload field lists each error once, with the spreadsheet rows that have it:
ExcelImportAction::make() ->validateUsing([ 'name' => 'required', 'email' => 'required|email', ]);
No rows were saved. Fix these rows and upload the file again: The name field is required. Row: 3. The email field must be a valid email address. Rows: 7, 9, 12, 15, 18 and 40 more.
Change the data before validation, and keep the change for the import by passing true:
ExcelImportAction::make() ->mutateBeforeValidationUsing(fn (array $data) => [...$data, 'email' => strtolower($data['email'])], true) ->validateUsing(['email' => 'email']);
Change the data after validation, right before it is saved:
ExcelImportAction::make() ->mutateAfterValidationUsing(fn (array $data) => [...$data, 'name' => ucwords($data['name'])]);
Extra data
Merge fixed values into every row:
ExcelImportAction::make() ->additionalData(['team_id' => auth()->user()->team_id]);
Custom import classes
Any Laravel Excel import class works. The constructor receives the model class, the extra use() arguments as an array and the additional data:
ExcelImportAction::make() ->use(ContactsImport::class, 'crm') ->customImportData(['source' => 'crm']);
Extend EnhancedDefaultImport to stop an import with a message, check headers and hook into each record:
use Illuminate\Support\Collection; use LucasDoro\SheetPilot\EnhancedDefaultImport; class ContactsImport extends EnhancedDefaultImport { protected function beforeCollection(Collection $collection): void { $this->validateHeaders(['name', 'email'], $collection); } protected function beforeCreateRecord(array $data, $row): void { if (Contact::where('email', $data['email'])->exists()) { $this->stopImportWithError("{$data['email']} is already registered."); } } }
stopImportWithError(), stopImportWithWarning(), stopImportWithInfo() and stopImportWithSuccess() show a notification of that type and keep the modal open.
Process the rows yourself without a class:
ExcelImportAction::make() ->processCollectionUsing(function (string $model, Collection $collection, array $additionalData) { foreach ($collection as $row) { $model::updateOrCreate(['email' => $row['email']], $row->toArray()); } return $collection; });
Hooks and extra fields
use Filament\Forms\Components\Select; ExcelImportAction::make() ->beforeUploadField([ Select::make('team_id')->options(Team::pluck('name', 'id')), ]) ->beforeImport(function (array $data, $livewire, $action) { $action->additionalData(['team_id' => $data['team_id']]); }) ->afterImport(function (array $data, $livewire) { // runs after the rows are saved });
Upload field
use Filament\Forms\Components\FileUpload; ExcelImportAction::make() ->acceptedFileTypes(['text/csv']) ->disk('s3') ->visibility('private') ->storeFiles(true) ->uploadField(fn (FileUpload $upload) => $upload->maxSize(2048));
Labels and notifications
The action is a regular Filament action, so the button and the modal use the usual methods:
ExcelImportAction::make() ->label('Import contacts') ->icon('heroicon-o-document-arrow-up') ->color('primary') ->modalHeading('Import contacts') ->modalDescription('Upload the spreadsheet exported from the CRM.') ->modalSubmitActionLabel('Import') ->uploadFieldLabel('Contacts file');
Notifications use Filament's notification methods. Set a title, change the whole notification, or pass null to send none:
use Filament\Notifications\Notification; ExcelImportAction::make() ->successNotificationTitle('Contacts imported') ->successNotification(fn (Notification $notification, ?int $savedRows) => $notification ->body("{$savedRows} contacts are ready.")) ->failureNotificationTitle('Could not import contacts') ->failureNotification(fn (Notification $notification, Throwable $exception, ?int $failedRow, ?int $savedRows) => $notification ->body("Check row {$failedRow}.")) ->stoppedNotification(fn (Notification $notification, string $type, string $message) => $notification ->title('Import stopped'));
$savedRows and $failedRow are null for custom import classes that do not count rows. The stopped notification is the one sent by stopImportWith*().
Every default text comes from the translation files. Publish them to change the wording for the whole app:
php artisan vendor:publish --tag=sheetpilot-translations
Sample file
Offer a sample spreadsheet built from an array:
ExcelImportAction::make() ->sampleExcel( sampleData: [ ['name' => 'Ana', 'email' => 'ana@example.com'], ], fileName: 'contacts.xlsx', sampleButtonLabel: 'Download template', customiseActionUsing: fn ($action) => $action->color('gray'), );
Or link to a file you host:
ExcelImportAction::make() ->sampleFileExcel('https://example.com/contacts.xlsx');
Relation managers
use LucasDoro\SheetPilot\Tables\ExcelImportRelationshipAction; public function table(Table $table): Table { return $table->headerActions([ ExcelImportRelationshipAction::make(), ]); }
Rows are saved through the relationship of the owner record. BelongsToMany relationships fill pivot columns from the matching spreadsheet columns.
Configuration
The config file has one option:
// config/sheetpilot.php return [ 'upload_disk' => null, ];
upload_disk is the disk used for uploads when the action does not call disk(). When it is null, SheetPilot reads excel-import.upload_disk from the original package, then falls back to the default filesystem disk.
Every message comes from lang/vendor/sheetpilot/{locale}/sheetpilot.php after publishing the translations. The package ships en, pt_BR, zh_CN and zh_TW. Laravel's own validation messages come from your application's language files.
Optional behavior
ExcelImportAction::make() ->authorizeCreate() ->deleteUploadedFile() ->useTransaction();
authorizeCreate()hides the action, and refuses to run it on the server, when creating is not allowed. Relation managers use their owncanCreate(), pages use the resource's, and the action stays hidden when neither exists.deleteUploadedFile()deletes the uploaded spreadsheet after a successful import.useTransaction(?string $connection = null)wraps the import in a transaction on the model's connection, or on the connection you pass.
useTransaction() and deleteUploadedFile() throw a LogicException when the import class implements ShouldQueue, because the transaction would not cover the queued job and the job would read a deleted file.
Errors and transactions
Laravel Excel already wraps every import in a transaction on the default database connection (excel.transactions.handler). With that default, an error or a stopImportWith*() call undoes every row saved by the import, including stopImportWithSuccess().
When the default import hits an error, SheetPilot reports the exception, keeps the modal open and shows where it stopped:
The import stopped at row 4. No rows were saved.
If the transaction handler is disabled, or the model lives on another connection, the rows saved before the error stay in the database and the notification says how many:
The import stopped at row 4. 2 rows were saved before the error. Call useTransaction() on the action to save all rows or none.
Use useTransaction() in that case. Errors from custom import classes show a generic message and are reported as well.
API reference
All methods return the action, so they can be chained. Filament's own action methods (label, icon, color, modal*, visible, authorize and the rest) work as usual.
Import
| Method | Description |
|---|---|
use(?string $class = null, ...$attributes) |
Import class, and extra constructor arguments. Defaults to DefaultImport |
validateUsing(array $rules) |
Laravel validation rules applied to every row before anything is saved |
mutateBeforeValidationUsing(Closure $closure, bool $shouldRetainBeforeValidationMutation = false) |
Change each row before validation, and optionally keep the change for the import |
mutateAfterValidationUsing(Closure $closure) |
Change each row right before it is saved |
processCollectionUsing(Closure $closure) |
Handle the rows yourself. Receives the model class, the collection, the additional data and the after validation mutator |
additionalData(array $data) |
Values merged into every row |
customImportData(array $data) |
Values passed to the import class through setCustomImportData() |
beforeImport(Closure $closure) |
Runs before the import with the form data, the Livewire component and the action |
afterImport(Closure $closure) |
Runs after the rows are saved with the form data and the Livewire component |
authorizeCreate() |
Hides and blocks the action when the user cannot create records |
useTransaction(?string $connection = null) |
Wraps the import in a database transaction |
deleteUploadedFile(bool $condition = true) |
Deletes the uploaded file after a successful import |
Upload field
| Method | Description |
|---|---|
uploadFieldLabel(string|Closure|null $label) |
Label of the upload field. Defaults to Spreadsheet |
uploadField(Closure $closure) |
Receives the FileUpload component and returns it changed |
beforeUploadField(array $fields) |
Form fields shown above the upload field |
afterUploadField(array $fields) |
Form fields shown below the upload field |
acceptedFileTypes(array $types) |
MIME types accepted by the browser |
disk(string $disk) |
Disk for the upload |
visibility(string|Closure|null $visibility) |
Visibility of the stored file. Defaults to public |
storeFiles(bool $storeFiles) |
Store the upload on the disk instead of reading the temporary file. Defaults to false |
Sample file
| Method | Description |
|---|---|
sampleExcel(array $sampleData, ?string $fileName = null, ?string $exportClass = null, ?string $sampleButtonLabel = null, ?Closure $customiseActionUsing = null) |
Adds a button that downloads a spreadsheet built from the array |
sampleFileExcel(string $url, ?string $sampleButtonLabel = null, ?Closure $customiseActionUsing = null) |
Adds a button that links to a hosted file |
Notifications
| Method | Closure arguments |
|---|---|
successNotificationTitle(string|Closure|null $title) |
|
successNotification(Notification|Closure|null $notification) |
$notification, $savedRows |
failureNotificationTitle(string|Closure|null $title) |
|
failureNotificationBody(string|Closure|null $body) |
|
failureNotification(Notification|Closure|null $notification) |
$notification, $exception, $failedRow, $savedRows |
stoppedNotification(Notification|Closure|null $notification) |
$notification, $type, $message |
Passing null to successNotification(), failureNotification() or stoppedNotification() turns that notification off.
Import classes
DefaultImport and DefaultRelationshipImport can be extended. EnhancedDefaultImport and EnhancedDefaultRelationshipImport add the CanStopImport methods.
| Method | Description |
|---|---|
beforeCollection(Collection $collection) |
Runs once before the rows are saved |
beforeCreateRecord(array $data, $row) |
Runs before each record is saved |
afterCreateRecord(array $data, $row) |
Runs after each record is saved. The relationship import also receives the record |
afterCollection(Collection $collection) |
Runs once after the rows are saved |
stopImportWithError(string $message), stopImportWithWarning(), stopImportWithInfo(), stopImportWithSuccess() |
Stops the import and shows a notification of that type |
validateHeaders(array $expectedHeaders, Collection $collection) |
Stops the import when a header is missing |
validateCustomCondition(bool $condition, string $errorMessage) |
Stops the import when the condition is false |
Testing
Test the action with Livewire like any other Filament action:
use Illuminate\Http\UploadedFile; use Livewire\Livewire; it('imports contacts', function () { $file = UploadedFile::fake()->createWithContent( 'contacts.csv', "name,email\nAna,ana@example.com\n", ); Livewire::test(ListContacts::class) ->callAction('import', data: ['upload' => $file]) ->assertNotified('Import complete'); expect(Contact::count())->toBe(1); });
Compatibility
| Laravel 11 | Laravel 12 | Laravel 13 | |
|---|---|---|---|
| Filament 4 | PHP 8.2 - 8.4 | PHP 8.2 - 8.4 | PHP 8.3 - 8.4 |
| Filament 5 | PHP 8.2 - 8.4 | PHP 8.2 - 8.4 | PHP 8.3 - 8.4 |
Every combination in the table runs in CI. PHP 8.5 follows once Laravel Excel supports it.
Known limits
- The import runs during the request. Large files can hit
max_execution_timeor the memory limit. As a reference, a 5,000-row, 10-column XLSX with validation took about 23 seconds and 122 MB of memory on a laptop with SQLite. For big files, use your own import class with Laravel Excel'sShouldQueueandWithChunkReading. - There is no limit on the number of rows.
- Uploading the same file twice saves the rows twice. Use a unique index and
processCollectionUsing()withupdateOrCreate()if that matters. - The default import does not go through the panel's tenancy. In a tenant panel, pass the tenant with
additionalData(). - Row numbers in messages assume the header is on the first row.
- Formulas are imported as their text (
=SUM(...)) and dates as Excel serial numbers. Convert them withmutateAfterValidationUsing(). HasManyThroughrelationships save records without linking them to the owner, as in the original package.
Security
- The default import uses the spreadsheet headers as model attributes. Use
$fillable, or validate the columns withvalidateUsing(), so a file cannot set columns such asis_admin. - The upload field blocks file paths sent by the browser, and the action only imports a file uploaded in the same request unless
storeFiles(true)is on. - With
storeFiles(true), the uploaded file stays on the disk until you calldeleteUploadedFile(). With the defaultstoreFiles(false), Livewire's temporary upload is read and Livewire cleans it up. Uploads arepublicby default, as in the original package. Passvisibility('private')when the disk is public. - Report vulnerabilities privately as described in SECURITY.md. Do not open a public issue.
Contributing
Bug reports and pull requests are welcome. See CONTRIBUTING.md for how to run the tests and what a pull request needs.
Changelog
See CHANGELOG.md.
Credits
The API follows eightynine/filament-excel-import by Eighty Nine, released under the MIT license. SheetPilot is a separate implementation.
License
The MIT License (MIT). See LICENSE.md.

