Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
quintenbuis committed Jan 7, 2022
0 parents commit 723e8d9
Show file tree
Hide file tree
Showing 10 changed files with 261 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE.md
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.
64 changes: 64 additions & 0 deletions README.md
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.
33 changes: 33 additions & 0 deletions composer.json
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"
]
}
}
}
13 changes: 13 additions & 0 deletions config/filament-settings.php
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')
]
];
8 changes: 8 additions & 0 deletions resources/views/components/values.blade.php
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>
3 changes: 3 additions & 0 deletions resources/views/pages/settings.blade.php
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>
54 changes: 54 additions & 0 deletions src/Components/RenderValues.php
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');
}
}
8 changes: 8 additions & 0 deletions src/FilamentSettings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Reworck\FilamentSettings;

class FilamentSettings
{

}
35 changes: 35 additions & 0 deletions src/FilamentSettingsProvider.php
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');
}
}
22 changes: 22 additions & 0 deletions src/Pages/Settings.php
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');
}
}

0 comments on commit 723e8d9

Please sign in to comment.