Coder Social home page Coder Social logo

bsormagec / laravel-nova-csv-import Goto Github PK

View Code? Open in Web Editor NEW

This project forked from simonhamp/laravel-nova-csv-import

0.0 1.0 0.0 502 KB

A simple CSV import component for Laravel Nova

Home Page: https://novapackages.com/packages/simonhamp/laravel-nova-csv-import

License: MIT License

Vue 33.52% JavaScript 3.83% PHP 58.93% SCSS 0.07% Blade 3.65%

laravel-nova-csv-import's Introduction

Laravel Nova CSV Import

Latest Stable Version Total Downloads License

A simple CSV import tool for Laravel Nova. This package builds on top of the great work done by Sparclex with the nova-import-card package.

Laravel Nova CSV Import Screenshot

Installation

Install via Composer:

composer require simonhamp/laravel-nova-csv-import

Once installed, you must register the component in your app's NovaServiceProvider (app/Providers/NovaServiceProvider.php):

namespace App\Providers;

use SimonHamp\LaravelNovaCsvImport\LaravelNovaCsvImport;

class NovaServiceProvider extends NovaApplicationServiceProvider
{
    public function tools()
    {
        return [
            new LaravelNovaCsvImport,
        ];
    }
}

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.

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 more information about how importing works here.

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=nova-csv-import

Then, define and register your own importer class:

<?php

return [
    'importer' =>  App\Utilities\Importer::class,
];

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.

laravel-nova-csv-import's People

Contributors

0x15f avatar monaye avatar ruerdev avatar septoctobre avatar simonhamp avatar zakini avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.