think.studio/nova-resource-dynamic-export 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

think.studio/nova-resource-dynamic-export

最新稳定版本:1.0.0

Composer 安装命令:

composer require think.studio/nova-resource-dynamic-export

包简介

Functionality to dynamically export resources.

README 文档

README

Packagist License Packagist Version Total Downloads Build Status Code Coverage Scrutinizer Code Quality

Functionality to dynamically export resources.

Nova Package
V4 V1

Installation

You can install the package via composer:

composer require think.studio/nova-resource-dynamic-export

# optional publish configs
php artisan vendor:publish --provider="NovaResourceDynamicExport\ServiceProvider" --tag="config"

Update filesystem configuration if you will used default storage disk.

// config/filesystems.php
'exports'                            => [
    'driver' => 'local',
    'root'   => storage_path('app/exports'),
],

And add resource to your admin:

// Providers/NovaServiceProvider.php
protected function resources(): void
{
    parent::resources();
    Nova::resources([
        \NovaResourceDynamicExport\Nova\Resources\ExportStoredFile::class,
    ]);
}

Please do not forget add policies for \NovaResourceDynamicExport\Models\ExportStoredFile model or your custom model

Usage

General resources export action

public function actions(NovaRequest $request): array
{
    return [
        \NovaResourceDynamicExport\Nova\Actions\ExportResourceAction::make()
            ->askForFilename()
            ->askForWriterType()
            ->askForColumns([
                'id',
                'title' => 'Fund title',
                'publication_status',
                'description',
                'color_code',
                'selected_report',
            ])
            ->setPostReplaceFieldValuesWhenOnResource(function ($array, \App\Models\Fund $model, $only) {
                if (in_array('selected_report', $only)) {
                    $array['selected_report'] = $model->selectedReport->report_date?->format('Y-m-d');
                }
                return $array;
            }),
    ];
}

Custom specified export

Firstly create custom export class

// Exports/PostsWithTagBreaking.php
use Illuminate\Database\Eloquent\Builder;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;
use NovaResourceDynamicExport\Export\CustomExport;
use NovaResourceDynamicExport\Tests\Fixtures\Models\Post;

class PostsWithTagBreaking extends CustomExport implements FromQuery, WithHeadings, WithMapping
{
    use Exportable;

    public function query()
    {
        return Post::query()
            ->whereHas('tags', fn (Builder $q) => $q->where('name', 'Breaking'));
    }

    public function headings(): array
    {
        return [
            'Title',
            'content',
        ];
    }

    /**
     * @param Post $row
     */
    public function map($row): array
    {

        return [
            'title'   => $row->title,
            'content' => $row->content,
        ];
    }
}

Then add this class using any service provider:

// Providers/NovaServiceProvider.php
public function boot(): void
{
    parent::boot();

    CustomResourcesExport::use(PostsWithTagBreaking::class);
}

THis is all, not in ExportStoredFile resource index you will see new action to run custom exports

Credits

  • Think Studio

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-09-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固