-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ea62aba
Showing
12 changed files
with
322 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) Dries Vints | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
[![Stand With Palestine](https://raw.githubusercontent.com/TheBSD/StandWithPalestine/main/banner-no-action.svg)](https://TheBSD.github.io/StandWithPalestine/) | ||
|
||
![Filament Excel.png](https://banners.beyondco.de/Filament%20Excel.png?theme=light&packageManager=composer+require&packageName=yemenopensource%2Ffilament-excel&pattern=architect&style=style_1&description=The+easiest+way+to+work+with+%22Excel%22&md=1&showWatermark=1&fontSize=100px&images=table) | ||
|
||
# Filament Excel | ||
|
||
The easiest way to work with "Excel", you only need to get fimiliar with [Laravel Excel](https://github.com/SpartnerNL/Laravel-Excel) to supercharged Excel exports and imports on your filament projects. | ||
|
||
|
||
## Installation | ||
|
||
You can install the package via Composer: | ||
|
||
```bash | ||
composer require yemenopensource/filament-excel | ||
``` | ||
|
||
## Usage | ||
Create [Create a new Import](https://docs.laravel-excel.com/3.1/imports/) for your model for example 'Content' model. | ||
|
||
```php | ||
php artisan make:import ContentsImport --model=Content | ||
``` | ||
|
||
Use the `Import` action on your filament resouce list page for example 'ListContents' page is a page to list the records of 'ContentResource': | ||
|
||
```php | ||
// app\Filament\Resources\ContentResource\Pages\ListContents.php | ||
|
||
use YOS\FilamentExcel\Actions\Import; | ||
|
||
protected function getHeaderActions(): array | ||
{ | ||
return [ | ||
// ... other actions like 'CreateAction' | ||
Import::make() | ||
->import(ContentsImport::class) | ||
->type(\Maatwebsite\Excel\Excel::XLSX) | ||
->label('Import from excel') | ||
->hint('Upload xlsx type') | ||
->icon(HeroIcons::C_ARROW_UP) | ||
->color('success'), | ||
]; | ||
} | ||
``` | ||
|
||
## Configuration | ||
|
||
The package provides a configuration file that allows you to customize its behavior. | ||
|
||
You can publish the configuration file by using the following command: | ||
|
||
```bash | ||
php artisan vendor:publish --provider="YOS\FilamentExcel\ServiceProvider" --tag="config" | ||
``` | ||
|
||
After publishing the configuration file, you can find it at config/filamentExcel.php. Open this file and modify it according to your requirements. | ||
|
||
## Translations | ||
|
||
You can publish translations using: | ||
|
||
```bash | ||
php artisan vendor:publish --provider="YOS\FilamentExcel\ServiceProvider" --tag="config" | ||
``` | ||
|
||
When users of the package execute Laravel's `vendor:publish` Artisan command, the package's language files will be published to `language path/vendor/filament-excel`. | ||
## Contributing | ||
|
||
Contributions are welcome! If you find any issues or have suggestions for improvements, please feel free to create an issue or a pull request. | ||
|
||
## License | ||
|
||
The package is part of yemen open source and it is licensed under the MIT license. | ||
|
||
## Credits | ||
|
||
- [Muath Alsowadi](https://github.com/muath-ye) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"name": "yemenopensource/filament-excel", | ||
"description": "This package useful for importing excel files into models.", | ||
"type": "library", | ||
"version": "0.1.0", | ||
"require": { | ||
"maatwebsite/excel": "^3.1", | ||
"illuminate/support": "^11" | ||
}, | ||
"license": "MIT", | ||
"autoload": { | ||
"psr-4": { | ||
"YOS\\FilamentExcel\\": "src/" | ||
} | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "muathye", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"minimum-stability": "stable", | ||
"extra": { | ||
"laravel": { | ||
"providers": [ | ||
"YOS\\FilamentExcel\\ServiceProvider" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
return [ | ||
/* | ||
|-------------------------------------------------------------------------- | ||
| Note | ||
|-------------------------------------------------------------------------- | ||
| | ||
| This package depends on https://docs.laravel-excel.com/ and you can | ||
| configure importing excels by following up the documentaion of laravel | ||
| excel package. | ||
| | ||
*/ | ||
|
||
// TODO: add queueable concern see: https://docs.laravel-excel.com/3.1/imports/queued.html#queued-reading | ||
// TODO: make header skipable by configuration, see: https://stackoverflow.com/questions/56726778/how-to-skip-first-row-when-importing-file | ||
// TODO: make files formats, see https://docs.laravel-excel.com/3.1/imports/import-formats.html | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
return [ | ||
'' => '', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
namespace YOS\FilamentExcel\Actions; | ||
|
||
use Closure; | ||
use Filament\Actions; | ||
use Filament\Forms\Components\FileUpload; | ||
use Filament\Support\Facades\FilamentIcon; | ||
use Maatwebsite\Excel\Facades\Excel; | ||
use YOS\FilamentExcel\Concerns; | ||
|
||
class Import extends Actions\Action | ||
{ | ||
use Concerns\HasImport; | ||
use Concerns\HasType; | ||
use Concerns\HasHint; | ||
|
||
protected ?Closure $getRelationshipUsing = null; | ||
protected bool | Closure $canCreateAnother = true; | ||
|
||
public static function getDefaultName(): ?string | ||
{ | ||
return 'import'; | ||
} | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->label(fn (): string => __('filament-actions::create.single.label', ['label' => $this->getModelLabel()])); | ||
|
||
$this->modalHeading(fn (): string => __('filament-actions::create.single.modal.heading', ['label' => $this->getModelLabel()])); | ||
|
||
$this->modalSubmitActionLabel(__('filament-actions::create.single.modal.actions.create.label')); | ||
|
||
$this->extraModalFooterActions(function (): array { | ||
return $this->canCreateAnother() ? [ | ||
$this->makeModalSubmitAction('createAnother', arguments: ['another' => true]) | ||
->label(__('filament-actions::create.single.modal.actions.create_another.label')), | ||
] : []; | ||
}); | ||
|
||
$this->successNotificationTitle(__('filament-actions::create.single.notifications.created.title')); | ||
|
||
$this->groupedIcon(FilamentIcon::resolve('actions::create-action.grouped') ?? 'heroicon-m-plus'); | ||
|
||
$this->form([ | ||
FileUpload::make('file') | ||
->hint(fn() => $this->getHint()) | ||
->storeFiles(false) | ||
]); | ||
|
||
$this->action(function (array $arguments, $form, $data): void { | ||
Excel::import(new ($this->getImport()), $data['file'], null, $this->getType()); | ||
$this->success(); | ||
}); | ||
} | ||
|
||
public function relationship(?Closure $relationship): static | ||
{ | ||
$this->getRelationshipUsing = $relationship; | ||
|
||
return $this; | ||
} | ||
public function canCreateAnother(): bool | ||
{ | ||
return (bool) $this->evaluate($this->canCreateAnother); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace YOS\FilamentExcel\Concerns; | ||
|
||
trait HasHint | ||
{ | ||
protected string $hintName; | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getHint() | ||
{ | ||
return $this->hintName; | ||
} | ||
|
||
public function hint(string $hintName): static | ||
{ | ||
$this->hintName = $hintName; | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace YOS\FilamentExcel\Concerns; | ||
|
||
trait HasImport | ||
{ | ||
protected string $importName; | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getImport() | ||
{ | ||
return $this->importName; | ||
} | ||
|
||
public function import(string $importName): static | ||
{ | ||
$this->importName = $importName; | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace YOS\FilamentExcel\Concerns; | ||
|
||
trait HasType | ||
{ | ||
protected string $typeName; | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getType() | ||
{ | ||
return $this->typeName; | ||
} | ||
|
||
public function type(string $typeName): static | ||
{ | ||
$this->typeName = $typeName; | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace YOS\FilamentExcel; | ||
|
||
use Illuminate\Support\ServiceProvider as SupportServiceProvider; | ||
|
||
class ServiceProvider extends SupportServiceProvider | ||
{ | ||
public function register() | ||
{ | ||
$this->mergeConfigFrom(__DIR__ . '/../config/config.php', 'filamentexcel'); | ||
} | ||
|
||
/** | ||
* Perform post-registration booting of services. | ||
* | ||
* @return void | ||
*/ | ||
public function boot() | ||
{ | ||
$this->publishes([ | ||
__DIR__ . '/config/config.php' => config_path('filamentexcel.php'), | ||
], 'config'); | ||
|
||
$this->loadTranslationsFrom(__DIR__ . '/../lang', 'filament-excel'); | ||
|
||
$this->publishes([ | ||
__DIR__.'/../lang' => $this->app->langPath('vendor/filament-excel'), | ||
]); | ||
} | ||
} |