-
Notifications
You must be signed in to change notification settings - Fork 11
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 723e8d9
Showing
10 changed files
with
261 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) Reworck <[email protected]> | ||
|
||
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,64 @@ | ||
# Filament settings | ||
|
||
This package allows for easy setting management using [Spatie's ValueStore package](https://github.com/spatie/valuestore) | ||
|
||
## Content of the configuration file | ||
```php | ||
return [ | ||
// Group the menu item belongs to | ||
'group' => 'Settings', | ||
|
||
// Sidebar label | ||
'label' => 'Settings', | ||
|
||
// Path to the file to be used as storage | ||
'path' => storage_path('app/settings.json'), | ||
|
||
// The fields to be stored | ||
'fields' => [ | ||
\Filament\Forms\Components\TextInput::make('title') | ||
] | ||
]; | ||
``` | ||
|
||
## Installation | ||
|
||
1. Require the package | ||
```shell | ||
composer require reworck/filament-settings | ||
``` | ||
|
||
2. publish the configuration file | ||
```shell | ||
php artisan vendor:publish --tag=filament-settings-config | ||
``` | ||
|
||
4. (Optionally) you can publish the views for the page and the view used by the livewire component | ||
```shell | ||
php artisan vendor:publish --tag=filament-settings-views | ||
``` | ||
|
||
## Usage | ||
|
||
To use this package fill in the `fields` array in the published config file. | ||
When saving the form the contents will be stored inside the specified file. | ||
|
||
After that you can access your values as you usually would using [spatie/valuestore](https://github.com/spatie/valuestore) | ||
|
||
## Testing | ||
```shell | ||
composer test | ||
``` | ||
|
||
## Security | ||
|
||
If you discover any security related issues, please email [email protected] instead of using the issue tracker. | ||
|
||
## Credits | ||
|
||
- [Quinten Buis](https://github.com/quintenbuis) | ||
- [All Contributors](../../contributors) | ||
|
||
## License | ||
|
||
The MIT License (MIT). Please see [License File](LICENSE.md) for more information. |
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,33 @@ | ||
{ | ||
"name": "reworck/filament-settings", | ||
"description": "Manage your settings in filament for spatie/valuestore", | ||
"authors": [ | ||
{ | ||
"name": "quintenbuis", | ||
"email": "[email protected]", | ||
"role": "Developer" | ||
} | ||
], | ||
"require": { | ||
"php": "^8.0", | ||
"spatie/valuestore": "^1.2", | ||
"livewire/livewire": "^v2.8.2" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Reworck\\FilamentSettings\\": "src" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"ShuvroRoy\\FilamentSettings\\Tests\\": "tests" | ||
} | ||
}, | ||
"extra": { | ||
"laravel": { | ||
"providers": [ | ||
"Reworck\\FilamentSettings\\FilamentSettingsProvider" | ||
] | ||
} | ||
} | ||
} |
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,13 @@ | ||
<?php | ||
|
||
return [ | ||
'group' => 'Settings', | ||
|
||
'label' => 'Settings', | ||
|
||
'path' => storage_path('app/settings.json'), | ||
|
||
'fields' => [ | ||
\Filament\Forms\Components\TextInput::make('title') | ||
] | ||
]; |
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,8 @@ | ||
<form wire:submit.prevent="submit"> | ||
|
||
{{ $this->form }} | ||
|
||
<x-tables::button type="submit" class="mt-2"> | ||
Save | ||
</x-tables::button> | ||
</form> |
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,3 @@ | ||
<x-filament::page> | ||
@livewire(\Reworck\FilamentSettings\Components\RenderValues::class) | ||
</x-filament::page> |
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,54 @@ | ||
<?php | ||
|
||
namespace Reworck\FilamentSettings\Components; | ||
|
||
use Filament\Forms\Concerns\InteractsWithForms; | ||
use Filament\Forms\Contracts\HasForms; | ||
use Illuminate\Contracts\View\View; | ||
use Livewire\Component; | ||
use Spatie\Valuestore\Valuestore; | ||
|
||
class RenderValues extends Component implements HasForms | ||
{ | ||
use InteractsWithForms; | ||
|
||
public array $data; | ||
|
||
protected function getFormStatePath(): string | ||
{ | ||
return 'data'; | ||
} | ||
|
||
public function filePath(): string | ||
{ | ||
return config('filament-settings.path'); | ||
} | ||
|
||
protected function getFormSchema(): array | ||
{ | ||
return config('filament-settings.fields'); | ||
} | ||
|
||
public function mount(): void | ||
{ | ||
$this->form->fill( | ||
Valuestore::make( | ||
$this->filePath() | ||
)->all() | ||
); | ||
} | ||
|
||
public function submit(): void | ||
{ | ||
foreach ($this->data as $key => $data) { | ||
Valuestore::make( | ||
$this->filePath() | ||
)->put($key, $data); | ||
} | ||
} | ||
|
||
public function render(): View | ||
{ | ||
return view('filament-settings::components.values'); | ||
} | ||
} |
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,8 @@ | ||
<?php | ||
|
||
namespace Reworck\FilamentSettings; | ||
|
||
class FilamentSettings | ||
{ | ||
|
||
} |
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,35 @@ | ||
<?php | ||
|
||
namespace Reworck\FilamentSettings; | ||
|
||
use Filament\PluginServiceProvider; | ||
use Livewire\Livewire; | ||
use Reworck\FilamentSettings\Components\RenderValues; | ||
use Reworck\FilamentSettings\Pages\Settings; | ||
use Spatie\LaravelPackageTools\Package; | ||
|
||
class FilamentSettingsProvider extends PluginServiceProvider | ||
{ | ||
public static string $name = 'filament-settings'; | ||
|
||
protected function getPages(): array | ||
{ | ||
return [ | ||
Settings::class, | ||
]; | ||
} | ||
|
||
public function packageBooted(): void | ||
{ | ||
parent::packageBooted(); | ||
|
||
Livewire::component(RenderValues::getName(), RenderValues::class); | ||
} | ||
|
||
public function configurePackage(Package $package): void | ||
{ | ||
parent::configurePackage($package); | ||
|
||
$package->hasConfigFile('filament-settings'); | ||
} | ||
} |
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,22 @@ | ||
<?php | ||
|
||
namespace Reworck\FilamentSettings\Pages; | ||
|
||
use Filament\Pages\Page; | ||
|
||
class Settings extends Page | ||
{ | ||
protected static ?string $navigationIcon = 'heroicon-o-cog'; | ||
|
||
protected static string $view = 'filament-settings::pages.settings'; | ||
|
||
protected static function getNavigationGroup(): ?string | ||
{ | ||
return config('filament-settings.group'); | ||
} | ||
|
||
protected static function getNavigationLabel(): string | ||
{ | ||
return config('filament-settings.label'); | ||
} | ||
} |