65 lines
1.7 KiB
PHP
65 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\SettingResource\Pages;
|
|
|
|
use App\Filament\Resources\SettingResource;
|
|
use App\Models\Setting;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Forms\Concerns\InteractsWithForms;
|
|
use Filament\Forms\Contracts\HasForms;
|
|
use Filament\Forms\Form;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Pages\Page;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Settings extends Page implements HasForms
|
|
{
|
|
use InteractsWithForms;
|
|
|
|
protected static string $resource = SettingResource::class;
|
|
|
|
protected static ?string $navigationIcon = 'heroicon-o-cog';
|
|
|
|
protected static ?string $navigationGroup = 'Settings';
|
|
|
|
protected static ?string $navigationLabel = 'Global Settings';
|
|
|
|
protected static ?string $slug = 'global-settings';
|
|
|
|
protected static string $view = 'filament.resources.setting-resource.pages.settings';
|
|
|
|
public ?array $data = [];
|
|
|
|
public function mount(): void
|
|
{
|
|
$this->form->fill(
|
|
collect(Setting::all())
|
|
->mapWithKeys(fn (Setting $setting) => [$setting->key => $setting->value])
|
|
->all()
|
|
);
|
|
}
|
|
|
|
public function form(Form $form): Form
|
|
{
|
|
return $form
|
|
->schema([
|
|
TextInput::make('gallery_heading')
|
|
->label(__('settings.gallery_heading')),
|
|
])
|
|
->statePath('data')
|
|
->model(Setting::class);
|
|
}
|
|
|
|
public function submit(): void
|
|
{
|
|
foreach ($this->form->getState() as $key => $value) {
|
|
Setting::updateOrCreate(['key' => $key], ['value' => $value]);
|
|
}
|
|
|
|
Notification::make()
|
|
->title(__('settings.saved_successfully'))
|
|
->success()
|
|
->send();
|
|
}
|
|
}
|