PHPackages                             martiallabs/laravel-nova-csv-import - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. martiallabs/laravel-nova-csv-import

ActiveLibrary

martiallabs/laravel-nova-csv-import
===================================

A fully-fledged CSV import tool for Laravel Nova.

1.0.0(1y ago)0311MITPHPPHP ^8.0

Since May 16Pushed 1y agoCompare

[ Source](https://github.com/MartialLabs/laravel-nova-csv-import)[ Packagist](https://packagist.org/packages/martiallabs/laravel-nova-csv-import)[ GitHub Sponsors](https://github.com/sponsors/simonhamp)[ RSS](/packages/martiallabs-laravel-nova-csv-import/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

Laravel Nova CSV Import
=======================

[](#laravel-nova-csv-import)

[![Latest Stable Version](https://camo.githubusercontent.com/cf7f26cd89a51000f309ee501ab18105896ca28d2cde155f1a215f78308fb782/68747470733a2f2f706f7365722e707567782e6f72672f73696d6f6e68616d702f6c61726176656c2d6e6f76612d6373762d696d706f72742f762f737461626c653f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/simonhamp/laravel-nova-csv-import) [![Total Downloads](https://camo.githubusercontent.com/38696dbf54829853fb7c35a71f2fddb81508ff2cfa2341bbf8a15a1ab67138cd/68747470733a2f2f706f7365722e707567782e6f72672f73696d6f6e68616d702f6c61726176656c2d6e6f76612d6373762d696d706f72742f646f776e6c6f6164733f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/simonhamp/laravel-nova-csv-import) [![License](https://camo.githubusercontent.com/77aebdd03b30b27c5f5485e6fc81976ff15dbd7e2975da182489767448acbb8a/68747470733a2f2f706f7365722e707567782e6f72672f73696d6f6e68616d702f6c61726176656c2d6e6f76612d6373762d696d706f72742f6c6963656e73653f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/simonhamp/laravel-nova-csv-import)

[![RINGER](https://camo.githubusercontent.com/7c01e0157b33865c7fbd5ddf1740b496846527a9605305528f0fd103bf436ee3/68747470733a2f2f7777772e72696e67657268712e636f6d2f696d616765732f6765742d737570706f72742d6f6e2d72696e6765722e737667)](https://www.ringerhq.com/i/simonhamp/laravel-nova-csv-import)

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](https://github.com/Sparclex/nova-import-card) package.

[![Laravel Nova CSV Import Screenshot](https://raw.githubusercontent.com/simonhamp/laravel-nova-csv-import/master/screenshots/readme.png)](https://raw.githubusercontent.com/simonhamp/laravel-nova-csv-import/master/screenshots/readme.png)

**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
-----------

[](#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](https://github.com/sponsors/simonhamp)

Thank you 🙏

Sponsors
--------

[](#sponsors)

[Laradir](https://laradir.com/?ref=laravel-nova-csv-import-github) - Connecting the best Laravel Developers with the best Laravel Teams

Installation
------------

[](#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-nova-main-menu)

If you have [customised your main menu](https://nova.laravel.com/docs/4.0/customization/menus.html#customizing-the-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
-------

[](#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

[](#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

[](#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
--------------

[](#importer-class)

This package uses [maatwebsite/excel](https://github.com/Maatwebsite/Laravel-Excel) behind the scenes to handle the actual import. You can find out more about [how importing works](https://docs.laravel-excel.com/3.1/imports/basics.html#importing-basics).

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:

```
