eightynine/filament-excel-import

Import Excel files with Laravel Filament.

v3.0.3 2024-03-19 04:38 UTC

This package is auto-updated.

Last update: 2024-04-21 06:43:29 UTC


README

Latest Version on Packagist Total Downloads

This package adds a new feature to your filament resource, allowing you to easily import data to your model

This package brings the maatwebsite/laravel-excel functionalities to filament. You can use all the maatwebsite/laravel-excel features in your laravel project

Installation

You can install the package via composer:

composer require eightynine/filament-excel-import

Usage

Before using this action, make sure to allow Mass Assignment for your model. If you are doing a custom import, this is not necessary.

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Client extends Model
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['name', 'phone', 'email'];
}

For example, if you have a 'ClientResource' in your project, integrate the action into ListClients class as demonstrated below:

namespace App\Filament\Resources\ClientResource\Pages;

use App\Filament\Resources\ClientResource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;

class ListClients extends ListRecords
{
    protected static string $resource = ClientResource::class;

    protected function getHeaderActions(): array
    {
        return [
            EightyNine\ExcelImport\ExcelImportAction::make()
                ->color("primary"),
            Actions\CreateAction::make(),
        ];
    }
}

Custom Import

If you wish to use your own import class to change the import procedure, you can use your own Import class.

php artisan make:import MyClientImport

Then in your action use your client imeport class

    protected function getHeaderActions(): array
    {
        return [
            \EightyNine\ExcelImport\ExcelImportAction::make()
                ->slideOver()
                ->color("primary")
                ->use(App\Imports\MyClientImport::class),
            Actions\CreateAction::make(),
        ];
    }

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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