- MoonShine 3+
- Laravel 10+
- PHP 8.2+
composer require moonshine/import-export
- Add
trait
MoonShine\ImportExport\Traits\ImportExportConcern
andinterface
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;
}