moonshine/import-export

Import/Export Handlers for MoonShine

1.0.1 2024-11-03 17:15 UTC

This package is auto-updated.

Last update: 2024-12-20 07:16:18 UTC


README

Documentation

Requirements

  • MoonShine 3+
  • Laravel 10+
  • PHP 8.2+

Installation

composer require moonshine/import-export

Usage

  • Add trait MoonShine\ImportExport\Traits\ImportExportConcern and interface MoonShine\ImportExport\Contracts\HasImportExportContract to ModelResource
/**
 * @extends ModelResource<Category>
 */
class CategoryResource extends ModelResource implements HasImportExportContract
{
    use ImportExportConcern;
    
    // ...
}
  • Define fields
/**
 * @extends ModelResource<Category>
 */
class CategoryResource extends ModelResource implements HasImportExportContract
{
    use ImportExportConcern;
    
    // ...
    
    protected function exportFields(): iterable
    {
        return [
            ID::make(),
            Position::make(),
            Text::make('Name'),
        ];
    }
    
    protected function importFields(): iterable
    {
        return [
            ID::make(),
            Text::make('Name'),
        ];
    }
}
  • Events
public function beforeImportFilling(array $data): array
{
    return $data;
}

public function beforeImported(mixed $item): mixed
{
    return $item;
}

public function afterImported(mixed $item): mixed
{
    return $item;
}