{"id":13733038,"url":"https://github.com/konnco/filament-import","last_synced_at":"2025-05-16T13:02:50.678Z","repository":{"id":58952375,"uuid":"534261405","full_name":"konnco/filament-import","owner":"konnco","description":"why import must use a template when you can import all files dynamically?","archived":false,"fork":false,"pushed_at":"2025-04-25T15:15:01.000Z","size":312,"stargazers_count":222,"open_issues_count":31,"forks_count":65,"subscribers_count":9,"default_branch":"filament3","last_synced_at":"2025-04-25T16:17:22.565Z","etag":null,"topics":["filamentphp","laravel-framework","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/konnco.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-09-08T14:53:44.000Z","updated_at":"2025-04-25T15:14:35.000Z","dependencies_parsed_at":"2024-06-18T21:37:23.626Z","dependency_job_id":"c3e41ebb-0515-411b-9776-692f523f9296","html_url":"https://github.com/konnco/filament-import","commit_stats":{"total_commits":143,"total_committers":18,"mean_commits":7.944444444444445,"dds":0.5874125874125874,"last_synced_commit":"e8d07dd30ad2b4bb7931870fde6a6bc7c119303e"},"previous_names":[],"tags_count":32,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/konnco%2Ffilament-import","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/konnco%2Ffilament-import/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/konnco%2Ffilament-import/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/konnco%2Ffilament-import/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/konnco","download_url":"https://codeload.github.com/konnco/filament-import/tar.gz/refs/heads/filament3","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254535826,"owners_count":22087398,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["filamentphp","laravel-framework","php"],"created_at":"2024-08-03T03:00:37.008Z","updated_at":"2025-05-16T13:02:50.654Z","avatar_url":"https://github.com/konnco.png","language":"PHP","funding_links":[],"categories":["Data Imports","Misc"],"sub_categories":[],"readme":"![Screenshot of Login](./art/screenshot.png)\n\n# Filament Plugin for Import CSV and XLS into Database\n\n\u003ca href=\"https://filamentadmin.com/docs/2.x/admin/installation\"\u003e\n    \u003cimg alt=\"FILAMENT 2.x\" src=\"https://img.shields.io/badge/FILAMENT-2.x-EBB304\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/konnco/filament-import\"\u003e\n    \u003cimg alt=\"Packagist\" src=\"https://img.shields.io/packagist/v/konnco/filament-import.svg?logo=packagist\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/konnco/filament-import\"\u003e\n    \u003cimg alt=\"Downloads\" src=\"https://img.shields.io/packagist/dt/konnco/filament-import.svg\" \u003e\n\u003c/a\u003e\n\n[![Code Styles](https://github.com/konnco/filament-import/actions/workflows/php-cs-fixer.yml/badge.svg)](https://github.com/konnco/filament-import/actions/workflows/php-cs-fixer.yml)\n[![run-tests](https://github.com/konnco/filament-import/actions/workflows/run-tests.yml/badge.svg)](https://github.com/konnco/filament-import/actions/workflows/run-tests.yml)\n\nThis package will make it easier for you to import from files to your model, very easily without the need to do templates.\n\nall you have to do is drag and drop and match the fields and columns of your file, and let magic happens!\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require konnco/filament-import\n```\n\n## Publishing Config\n\nIf you want to do the settings manually, please publish the existing config.\n\n```bash\nphp artisan vendor:publish --tag=filament-import-config\n```\n\n## Usage\n\nimport the actions into `ListRecords` page\n\n```php\nuse Konnco\\FilamentImport\\Actions\\ImportAction;\nuse Konnco\\FilamentImport\\Actions\\ImportField;\n\nclass ListCredentialDatabases extends ListRecords\n{\n    protected static string $resource = CredentialDatabaseResource::class;\n\n    protected function getActions(): array\n    {\n        return [\n            ImportAction::make()\n                -\u003efields([\n                    ImportField::make('project')\n                        -\u003elabel('Project')\n                        -\u003ehelperText('Define as project helper'),\n                    ImportField::make('manager')\n                        -\u003elabel('Manager'),\n                ])\n        ];\n    }\n}\n```\n### Required Field\n```php\nprotected function getActions(): array\n{\n    return [\n        ImportAction::make()\n            -\u003efields([\n                ImportField::make('project')\n                    -\u003elabel('Project')\n                    -\u003erequired(),\n            ])\n    ];\n}\n```\n\n### Disable Mass Create\nif you still want to stick with the event model you might need this and turn off mass create\n```php\nprotected function getActions(): array\n{\n    return [\n        ImportAction::make()\n            -\u003emassCreate(false)\n            -\u003efields([\n                ImportField::make('project')\n                    -\u003elabel('Project')\n                    -\u003erequired(),\n            ])\n    ];\n}\n```\n\n### Filter Out Blank Rows\nIf you have a spreadsheet which includes blank data [click here to see more](https://thesoftwarepro.com/excel-tips-how-to-fill-blank-cells/), you can filter these out:\n```php\nprotected function getActions(): array\n{\n    return [\n        ImportAction::make()\n            -\u003ehandleBlankRows(true)\n            -\u003efields([\n                ImportField::make('project')\n                    -\u003elabel('Project')\n                    -\u003erequired(),\n            ])\n    ];\n}\n```\n\n### Field Data Mutation\nyou can also manipulate data from row spreadsheet before saving to model\n```php\nprotected function getActions(): array\n{\n    return [\n        ImportAction::make()\n            -\u003efields([\n                ImportField::make('project')\n                    -\u003elabel('Project')\n                    -\u003emutateBeforeCreate(fn($value) =\u003e Str::of($value)-\u003ecamelCase())\n                    -\u003erequired(),\n            ])\n    ];\n}\n```\notherwise you can manipulate data and getting all mutated data from field before its getting insert into the database.\n```php\nprotected function getActions(): array\n{\n    return [\n        ImportAction::make()\n            -\u003efields([\n                ImportField::make('email')\n                    -\u003elabel('Email')\n                    -\u003erequired(),\n            ])-\u003emutateBeforeCreate(function($row){\n                $row['password'] = bcrypt($row['email']);\n\n                return $row;\n            })\n    ];\n}\n```\nit is also possible to manipulate data after it was inserted into the database\n```php\nuse Illuminate\\Database\\Eloquent\\Model;\n\nprotected function getActions(): array\n{\n    return [\n        ImportAction::make()\n            -\u003efields([\n                ImportField::make('email')\n                    -\u003elabel('Email')\n                    -\u003erequired(),\n            ])-\u003emutateAfterCreate(function(Model $model, $row){\n                // do something with the model\n\n                return $model;\n            })\n    ];\n}\n```\n\n### Grid Column\nOf course, you can divide the column grid into several parts to beautify the appearance of the data map\n```php\nprotected function getActions(): array\n{\n    return [\n        ImportAction::make()\n            -\u003efields([\n                ImportField::make('project')\n                    -\u003elabel('Project')\n                    -\u003erequired(),\n            ], columns:2)\n    ];\n}\n```\n\n### Json Format Field\nWe also support the json format field, which you can set when calling the `make` function and separate the name with a dot annotation\n\n```php\nprotected function getActions(): array\n{\n    return [\n        ImportAction::make()\n            -\u003efields([\n                ImportField::make('project.en')\n                    -\u003elabel('Project In English')\n                    -\u003erequired(),\n                ImportField::make('project.id')\n                    -\u003elabel('Project in Indonesia')\n                    -\u003erequired(),\n            ], columns:2)\n    ];\n}\n```\n\n### Static Field Data\nfor the static field data you can use the common fields from filament\n\n```php\nuse Filament\\Forms\\Components\\Select;\n\nprotected function getActions(): array\n{\n    return [\n        ImportAction::make()\n            -\u003efields([\n                ImportField::make('name')\n                    -\u003elabel('Project')\n                    -\u003erequired(),\n                Select::make('status')\n                    -\u003eoptions([\n                        'draft' =\u003e 'Draft',\n                        'reviewing' =\u003e 'Reviewing',\n                        'published' =\u003e 'Published',\n                    ])\n            ], columns:2)\n    ];\n}\n```\n\n### Unique field\nif your model should be unique, you can pass the name of the field, which will be used to check if a row already exists in the database. if it exists, skip that row (preventing an error about non unique row)\n\n```php\nuse Filament\\Forms\\Components\\Select;\n\nprotected function getActions(): array\n{\n    return [\n        ImportAction::make()\n            -\u003euniqueField('email')\n            -\u003efields([\n                ImportField::make('email')\n                    -\u003elabel('Email')\n                    -\u003erequired(),\n            ], columns:2)\n    ];\n}\n```\n\n### Validation\nyou can make the validation for import fields, for more information about the available validation please check laravel documentation\n\n```php\nuse Filament\\Forms\\Components\\Select;\n\nprotected function getActions(): array\n{\n    return [\n        ImportAction::make()\n            -\u003efields([\n                ImportField::make('name')\n                    -\u003elabel('Project')\n                    -\u003erules('required|min:10|max:255'),\n            ], columns:2)\n    ];\n}\n```\n\n### Create Record\nyou can overide the default record creation closure and put your own code by using `handleRecordCreation` function\n\n```php\nuse Filament\\Forms\\Components\\Select;\n\nprotected function getActions(): array\n{\n    return [\n        ImportAction::make()\n            -\u003efields([\n                ImportField::make('name')\n                    -\u003elabel('Project')\n                    -\u003erules('required|min:10|max:255'),\n            ], columns:2)\n            -\u003ehandleRecordCreation(function($data){\n                return Post::create($data);\n            })\n    ];\n}\n```\n\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/konnco/.github/blob/main/CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](../../security/policy) on how to report security vulnerabilities.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkonnco%2Ffilament-import","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkonnco%2Ffilament-import","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkonnco%2Ffilament-import/lists"}