Settings plugin

This commit is contained in:
Dan Harrin
2021-11-25 14:22:51 +00:00
parent cab77f6d0a
commit 61c96daa2d
8 changed files with 4171 additions and 0 deletions
+7
View File
@@ -43,6 +43,13 @@ composer require filament/tables
composer require filament/spatie-laravel-media-library-plugin
```
### spatie/laravel-settings Plugin • [Documentation](https://filamentadmin.com/docs/spatie-laravel-settings-plugin)
**Current version series:** v2.x.
```bash
composer require filament/spatie-laravel-settings-plugin
```
### spatie/laravel-tags Plugin • [Documentation](https://filamentadmin.com/docs/spatie-laravel-tags-plugin)
**Current version series:** v2.x.
@@ -0,0 +1 @@
/vendor
@@ -0,0 +1,32 @@
{
"name": "filament/spatie-laravel-settings-plugin",
"description": "Filament support for `spatie/laravel-settings`.",
"license": "MIT",
"homepage": "https://github.com/laravel-filament/filament",
"support": {
"issues": "https://github.com/laravel-filament/filament/issues",
"source": "https://github.com/laravel-filament/filament"
},
"require": {
"php": "^8.0",
"filament/filament": "self.version",
"spatie/laravel-settings": "^2.2"
},
"autoload": {
"psr-4": {
"Filament\\": "src"
}
},
"extra": {
"laravel": {
"providers": [
"Filament\\SpatieLaravelSettingsPluginServiceProvider"
]
}
},
"config": {
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,33 @@
---
title: Installation
---
## Requirements
Filament has a few requirements to run:
- PHP 8.0+
- Laravel v8.0+
- Livewire v2.0+
## Installation
Install the plugin with Composer:
```bash
composer require filament/spatie-laravel-settings-plugin
```
> Please note that this package is incompatible with `filament/filament` v1, until v2 is released in late 2021. This is due to namespacing collisions.
You're now ready to start building [settings pages](building-settings-pages)!
## Upgrade Guide
To upgrade the package to the latest version, you must run:
```bash
composer update
php artisan view:clear
```
@@ -0,0 +1,7 @@
<x-filament::page>
<x-filament::form wire:submit.prevent="save">
{{ $this->form }}
<x-filament::actions :actions="$this->getFormActions()" />
</x-filament::form>
</x-filament::page>
@@ -0,0 +1,90 @@
<?php
namespace Filament\Pages;
use Filament\Forms;
use Filament\View\Components\Actions\ButtonAction;
class SettingsPage extends Page implements Forms\Contracts\HasForms
{
use Forms\Concerns\InteractsWithForms;
protected static string $settings;
protected static string $view = 'filament-spatie-laravel-settings-plugin::pages.settings-page';
public $data;
public function mount(): void
{
$this->fillForm();
}
protected function fillForm(): void
{
$this->callHook('beforeFill');
$settings = app(static::$settings);
$this->form->fill($settings->toArray());
$this->callHook('afterFill');
}
public function save(): void
{
$this->callHook('beforeValidate');
$data = $this->form->getState();
$this->callHook('afterValidate');
$this->callHook('beforeSave');
$settings = app(static::$settings);
$settings->fill($data);
$settings->save();
$this->callHook('afterSave');
if ($redirectUrl = $this->getRedirectUrl()) {
$this->redirect($redirectUrl);
} else {
$this->notify('success', 'Saved!');
}
}
protected function callHook(string $hook): void
{
if (! method_exists($this, $hook)) {
return;
}
$this->{$hook}();
}
protected function getFormActions(): array
{
return [
ButtonAction::make('save')
->label('Save')
->submit(),
];
}
protected function getForms(): array
{
return [
'form' => $this->makeForm()
->schema($this->getFormSchema())
->statePath('data')
->columns(2),
];
}
protected function getRedirectUrl(): ?string
{
return null;
}
}
@@ -0,0 +1,14 @@
<?php
namespace Filament;
use Illuminate\Support\ServiceProvider;
class SpatieLaravelSettingsPluginServiceProvider extends ServiceProvider
{
public function boot(): void
{
$this->loadTranslationsFrom(__DIR__ . '/../resources/lang', 'filament-spatie-laravel-settings-plugin');
$this->loadViewsFrom(__DIR__ . '/../resources/views', 'filament-spatie-laravel-settings-plugin');
}
}