定制 kayacekovic/nova-import 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

kayacekovic/nova-import

最新稳定版本:0.0.8

Composer 安装命令:

composer require kayacekovic/nova-import

包简介

A Laravel Nova import tool.

README 文档

README

💡 Suggestion: Nova v3.10.0+ has ability to create "standalone" actions for running actions without selecting resources. you can create import action without using this package. Tutorial

Import data to resources.

Screenshot

Installation

You can install the package in to a Laravel app that uses Nova via composer:

composer require anaseqal/nova-import

Register the tool in your app/Providers/NovaServiceProvider.php:

use Anaseqal\NovaImport\NovaImport;

// ...

public function tools()
{
    return [
        new NovaImport,
        // ...
    ];
}

Usage

To use this tool, you need to create two things:

  1. Create an import class for your resource using Laravel Excel.

  2. Create a custom Nova Action file:

<?php

namespace App\Nova\Actions;

use Illuminate\Bus\Queueable;
use Anaseqal\NovaImport\Actions\Action;
use Illuminate\Support\Collection;
use Laravel\Nova\Fields\ActionFields;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Laravel\Nova\Fields\File;

use App\Imports\UsersImport;
use Maatwebsite\Excel\Facades\Excel;

class ImportUsers extends Action
{
    use InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Indicates if this action is only available on the resource detail view.
     *
     * @var bool
     */
    public $onlyOnIndex = true;

    /**
     * Get the displayable name of the action.
     *
     * @return string
     */
    public function name() {
        return __('Import Users');
    }

    /**
     * @return string
     */
    public function uriKey() :string
    {
        return 'import-users';
    }

    /**
     * Perform the action.
     *
     * @param  \Laravel\Nova\Fields\ActionFields  $fields
     * @return mixed
     */
    public function handle(ActionFields $fields)
    {
        Excel::import(new UsersImport, $fields->file);

        return Action::message('It worked!');
    }

    /**
     * Get the fields available on the action.
     *
     * @return array
     */
    public function fields()
    {
        return [
            File::make('File')
                ->rules('required'),
        ];
    }
}
  1. Register the action into your resource:
/**
 * Get the actions available for the resource.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return array
 */
public function actions(Request $request)
{
    return [new Actions\ImportUsers];
}

Action Name must use the Format of Import{ResourceName}, for example ImportUsers or ImportCountries.

Please note that it extends Anaseqal\NovaImport\Actions\Action not normal Nova Actions because it doesn't applies on models!

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 2.77k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 28
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-04-01