martiallabs/laravel-nova-csv-import
Composer 安装命令:
composer require martiallabs/laravel-nova-csv-import
包简介
A fully-fledged CSV import tool for Laravel Nova.
README 文档
README
A rich and powerful CSV import component for Laravel Nova. CSV Import allows you to easily upload CSV or Excel files and import their data into any Nova resource.
No need to make your file match your database! The import process lets you choose how to map the relevant columns from your uploaded file to the attributes on your models, with a nice summary at the end of what worked and what didn't.
You can even modify values as they're being imported to add hashing or other manipulations, set custom values, random values and now even combine multiple values to be imported into a single field!
This package was originally built on top of work done by Sparclex on the nova-import-card package.
NB: As of v0.4.0, CSV Import requires Nova v4 and above. For Nova versions prior to v4, please use a CSV Import v0.3.0 or lower. Please also be aware that versions prior to v0.4.0 will no longer be maintained.
Sponsorship
CSV Import is completely free to use for personal or commercial use. If it's making your job easier or you just want to make sure it keeps being supported and improved, I'd really appreciate your donations!
Donate now via GitHub Sponsors
Thank you 🙏
Sponsors
Laradir - Connecting the best Laravel Developers with the best Laravel Teams
Installation
Install via Composer:
composer require simonhamp/laravel-nova-csv-import --with-all-dependencies
Once installed, you must register the component in your app's NovaServiceProvider
(usually in app/Providers/NovaServiceProvider.php):
namespace App\Providers; use SimonHamp\LaravelNovaCsvImport\LaravelNovaCsvImport; class NovaServiceProvider extends NovaApplicationServiceProvider { public function tools() { return [ new LaravelNovaCsvImport, ]; } }
If you have customised your Nova main menu
If you have customised your main menu, then you will need to manually register the tool's menu item in your custom menu for it to appear.
For example, in your app/Providers/NovaServiceProvider.php:
public function boot() { parent::boot(); Nova::mainMenu(function (Request $request) { return [ // ... other custom menu items MenuSection::make('CSV Import') ->path('/csv-import') ->icon('upload'), ]; } }
Options
By default, all of your Nova Resources will be available for import. However, there are a number of ways that you can explicitly limit what's available for importing.
public static $canImportResource = false;
Default: true
Add this static property to your Resource to prevent it from showing up in the Nova CSV Import tool interface.
public static function canImportResource($request): bool
Define a canImportResource method to use more complex logic to decide if this Resource can be shown during import.
If defined, this takes precedence over the $canImportResource property.
Exclude certain fields
CSV Import aims to respect your Nova configuration, but there are times when you want your imports to behave slightly
differently to your Nova interface. For that you can use the excludeAttributesFromImport() method:
public static function excludeAttributesFromImport(): array
Default: []
Define a excludeAttributesFromImport method that returns an array of attribute names that you want to exclude from
being visible in the import tool for this Resource.
Example
// App\Nova\User public static function canImportResource(Request $request) { return $request->user()->can("create", self::$model); } public static function excludeAttributesFromImport() { return ['password']; }
Importer Class
This package uses maatwebsite/excel behind the scenes to handle the actual import. You can find out more about how importing works.
You can define your own importer class by providing the relevant class name in your published copy of this package's config file.
First, publish the config file:
php artisan vendor:publish --tag=csv-import
Then, define and register your own importer class:
<?php
return [
'importer' => App\Utilities\Importer::class,
];
Usage
CSV Import is a powerful tool, but I'm trying to make it simple and easy to use for anyone. For tips and tricks please check out my YouTube playlist.
Full documentation is coming.
Testing
We need tests! Can you help? Please consider contributing.
Contributing
Please see CONTRIBUTING for details.
License
The MIT License (MIT). Please see LICENSE for more details.
martiallabs/laravel-nova-csv-import 适用场景与选型建议
martiallabs/laravel-nova-csv-import 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 311 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 05 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「nova」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 martiallabs/laravel-nova-csv-import 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 martiallabs/laravel-nova-csv-import 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 martiallabs/laravel-nova-csv-import 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Nova card that shows you your system information.
A Laravel Nova card.
A Laravel Nova package for publishable fields
A Laravel Nova package for translatable fields
A Laravel Nova Image field. you can paste or drag or chose an image
A Laravel Nova Mail testing tool.
统计信息
- 总下载量: 311
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-05-16
