Skip to content

Commit ea62aba

Browse files
committed
⚡ init commit
0 parents  commit ea62aba

12 files changed

+322
-0
lines changed

LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) Dries Vints
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
[![Stand With Palestine](https://raw.githubusercontent.com/TheBSD/StandWithPalestine/main/banner-no-action.svg)](https://TheBSD.github.io/StandWithPalestine/)
2+
3+
![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)
4+
5+
# Filament Excel
6+
7+
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.
8+
9+
10+
## Installation
11+
12+
You can install the package via Composer:
13+
14+
```bash
15+
composer require yemenopensource/filament-excel
16+
```
17+
18+
## Usage
19+
Create [Create a new Import](https://docs.laravel-excel.com/3.1/imports/) for your model for example 'Content' model.
20+
21+
```php
22+
php artisan make:import ContentsImport --model=Content
23+
```
24+
25+
Use the `Import` action on your filament resouce list page for example 'ListContents' page is a page to list the records of 'ContentResource':
26+
27+
```php
28+
// app\Filament\Resources\ContentResource\Pages\ListContents.php
29+
30+
use YOS\FilamentExcel\Actions\Import;
31+
32+
protected function getHeaderActions(): array
33+
{
34+
return [
35+
// ... other actions like 'CreateAction'
36+
Import::make()
37+
->import(ContentsImport::class)
38+
->type(\Maatwebsite\Excel\Excel::XLSX)
39+
->label('Import from excel')
40+
->hint('Upload xlsx type')
41+
->icon(HeroIcons::C_ARROW_UP)
42+
->color('success'),
43+
];
44+
}
45+
```
46+
47+
## Configuration
48+
49+
The package provides a configuration file that allows you to customize its behavior.
50+
51+
You can publish the configuration file by using the following command:
52+
53+
```bash
54+
php artisan vendor:publish --provider="YOS\FilamentExcel\ServiceProvider" --tag="config"
55+
```
56+
57+
After publishing the configuration file, you can find it at config/filamentExcel.php. Open this file and modify it according to your requirements.
58+
59+
## Translations
60+
61+
You can publish translations using:
62+
63+
```bash
64+
php artisan vendor:publish --provider="YOS\FilamentExcel\ServiceProvider" --tag="config"
65+
```
66+
67+
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`.
68+
## Contributing
69+
70+
Contributions are welcome! If you find any issues or have suggestions for improvements, please feel free to create an issue or a pull request.
71+
72+
## License
73+
74+
The package is part of yemen open source and it is licensed under the MIT license.
75+
76+
## Credits
77+
78+
- [Muath Alsowadi](https://github.com/muath-ye)

art/Filament Excel.png

105 KB
Loading

art/banner-no-action.svg

+1
Loading

composer.json

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "yemenopensource/filament-excel",
3+
"description": "This package useful for importing excel files into models.",
4+
"type": "library",
5+
"version": "0.1.0",
6+
"require": {
7+
"maatwebsite/excel": "^3.1",
8+
"illuminate/support": "^11"
9+
},
10+
"license": "MIT",
11+
"autoload": {
12+
"psr-4": {
13+
"YOS\\FilamentExcel\\": "src/"
14+
}
15+
},
16+
"authors": [
17+
{
18+
"name": "muathye",
19+
"email": "[email protected]"
20+
}
21+
],
22+
"minimum-stability": "stable",
23+
"extra": {
24+
"laravel": {
25+
"providers": [
26+
"YOS\\FilamentExcel\\ServiceProvider"
27+
]
28+
}
29+
}
30+
}

config/config.php

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
return [
4+
/*
5+
|--------------------------------------------------------------------------
6+
| Note
7+
|--------------------------------------------------------------------------
8+
|
9+
| This package depends on https://docs.laravel-excel.com/ and you can
10+
| configure importing excels by following up the documentaion of laravel
11+
| excel package.
12+
|
13+
*/
14+
15+
// TODO: add queueable concern see: https://docs.laravel-excel.com/3.1/imports/queued.html#queued-reading
16+
// TODO: make header skipable by configuration, see: https://stackoverflow.com/questions/56726778/how-to-skip-first-row-when-importing-file
17+
// TODO: make files formats, see https://docs.laravel-excel.com/3.1/imports/import-formats.html
18+
];

lang/en/filament-excel.php

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
return [
4+
'' => '',
5+
];

src/Actions/Import.php

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
namespace YOS\FilamentExcel\Actions;
4+
5+
use Closure;
6+
use Filament\Actions;
7+
use Filament\Forms\Components\FileUpload;
8+
use Filament\Support\Facades\FilamentIcon;
9+
use Maatwebsite\Excel\Facades\Excel;
10+
use YOS\FilamentExcel\Concerns;
11+
12+
class Import extends Actions\Action
13+
{
14+
use Concerns\HasImport;
15+
use Concerns\HasType;
16+
use Concerns\HasHint;
17+
18+
protected ?Closure $getRelationshipUsing = null;
19+
protected bool | Closure $canCreateAnother = true;
20+
21+
public static function getDefaultName(): ?string
22+
{
23+
return 'import';
24+
}
25+
26+
protected function setUp(): void
27+
{
28+
parent::setUp();
29+
30+
$this->label(fn (): string => __('filament-actions::create.single.label', ['label' => $this->getModelLabel()]));
31+
32+
$this->modalHeading(fn (): string => __('filament-actions::create.single.modal.heading', ['label' => $this->getModelLabel()]));
33+
34+
$this->modalSubmitActionLabel(__('filament-actions::create.single.modal.actions.create.label'));
35+
36+
$this->extraModalFooterActions(function (): array {
37+
return $this->canCreateAnother() ? [
38+
$this->makeModalSubmitAction('createAnother', arguments: ['another' => true])
39+
->label(__('filament-actions::create.single.modal.actions.create_another.label')),
40+
] : [];
41+
});
42+
43+
$this->successNotificationTitle(__('filament-actions::create.single.notifications.created.title'));
44+
45+
$this->groupedIcon(FilamentIcon::resolve('actions::create-action.grouped') ?? 'heroicon-m-plus');
46+
47+
$this->form([
48+
FileUpload::make('file')
49+
->hint(fn() => $this->getHint())
50+
->storeFiles(false)
51+
]);
52+
53+
$this->action(function (array $arguments, $form, $data): void {
54+
Excel::import(new ($this->getImport()), $data['file'], null, $this->getType());
55+
$this->success();
56+
});
57+
}
58+
59+
public function relationship(?Closure $relationship): static
60+
{
61+
$this->getRelationshipUsing = $relationship;
62+
63+
return $this;
64+
}
65+
public function canCreateAnother(): bool
66+
{
67+
return (bool) $this->evaluate($this->canCreateAnother);
68+
}
69+
}

src/Concerns/HasHint.php

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace YOS\FilamentExcel\Concerns;
4+
5+
trait HasHint
6+
{
7+
protected string $hintName;
8+
9+
/**
10+
* @return mixed
11+
*/
12+
public function getHint()
13+
{
14+
return $this->hintName;
15+
}
16+
17+
public function hint(string $hintName): static
18+
{
19+
$this->hintName = $hintName;
20+
21+
return $this;
22+
}
23+
}

src/Concerns/HasImport.php

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace YOS\FilamentExcel\Concerns;
4+
5+
trait HasImport
6+
{
7+
protected string $importName;
8+
9+
/**
10+
* @return mixed
11+
*/
12+
public function getImport()
13+
{
14+
return $this->importName;
15+
}
16+
17+
public function import(string $importName): static
18+
{
19+
$this->importName = $importName;
20+
21+
return $this;
22+
}
23+
}

src/Concerns/HasType.php

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace YOS\FilamentExcel\Concerns;
4+
5+
trait HasType
6+
{
7+
protected string $typeName;
8+
9+
/**
10+
* @return mixed
11+
*/
12+
public function getType()
13+
{
14+
return $this->typeName;
15+
}
16+
17+
public function type(string $typeName): static
18+
{
19+
$this->typeName = $typeName;
20+
21+
return $this;
22+
}
23+
}

src/ServiceProvider.php

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace YOS\FilamentExcel;
4+
5+
use Illuminate\Support\ServiceProvider as SupportServiceProvider;
6+
7+
class ServiceProvider extends SupportServiceProvider
8+
{
9+
public function register()
10+
{
11+
$this->mergeConfigFrom(__DIR__ . '/../config/config.php', 'filamentexcel');
12+
}
13+
14+
/**
15+
* Perform post-registration booting of services.
16+
*
17+
* @return void
18+
*/
19+
public function boot()
20+
{
21+
$this->publishes([
22+
__DIR__ . '/config/config.php' => config_path('filamentexcel.php'),
23+
], 'config');
24+
25+
$this->loadTranslationsFrom(__DIR__ . '/../lang', 'filament-excel');
26+
27+
$this->publishes([
28+
__DIR__.'/../lang' => $this->app->langPath('vendor/filament-excel'),
29+
]);
30+
}
31+
}

0 commit comments

Comments
 (0)