by Franky So
import without the need to do templates. all you have to do is drag and drop and match the fields and columns of your file, and let the magic happens!
Filament Plugin for Import CSV and XLS into Database
This package will make it easier for you to import files to your model, very easily without the need to do templates.
all you have to do is drag and drop and match the fields and columns of your file, and let the magic happens!
You can install the package via composer:
composer require konnco/filament-import
If you want to do the settings manually, please publish the existing config.
php artisan vendor:publish --tag=filament-import-config
import the actions into ListRecords
page
use Konnco\FilamentImport\Actions\ImportAction;use Konnco\FilamentImport\ImportField; class ListCredentialDatabases extends ListRecords{ protected static string $resource = CredentialDatabaseResource::class; protected function getActions(): array { return [ ImportAction::make() ->fields([ ImportField::make('project') ->label('Project') ->helperText('Define as project helper'), ImportField::make('manager') ->label('Manager'), ]) ]; }}
protected function getActions(): array{ return [ ImportAction::make() ->fields([ ImportField::make('project') ->label('Project') ->required(), ]) ];}
if you still want to stick with the event model you might need this and turn off mass create
protected function getActions(): array{ return [ ImportAction::make() ->massCreate(false) ->fields([ ImportField::make('project') ->label('Project') ->required(), ]) ];}
you can also manipulate data from row spreadsheet before saving to model
protected function getActions(): array{ return [ ImportAction::make() ->fields([ ImportField::make('project') ->label('Project') ->mutateBeforeCreate(fn($string) => Str::of($string)->camelCase()) ->required(), ]) ];}
Of course, you can divide the column grid into several parts to beautify the appearance of the data map
protected function getActions(): array{ return [ ImportAction::make() ->fields([ ImportField::make('project') ->label('Project') ->required(), ], columns:2) ];}
We also support the json format field, which you can set when calling the make
function and separate the name with a dot annotation
protected function getActions(): array{ return [ ImportAction::make() ->fields([ ImportField::make('project.en') ->label('Project In English') ->required(), ImportField::make('project.id') ->label('Project in Indonesia') ->required(), ], columns:2) ];}
composer test