101 lines
3.7 KiB
PHP
101 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources;
|
|
|
|
use App\Filament\Resources\SettingResource\Pages;
|
|
use App\Filament\Resources\SettingResource\RelationManagers;
|
|
use App\Models\Setting;
|
|
use Filament\Forms;
|
|
use Filament\Forms\Form;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Tables;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Forms\Components\Fieldset;
|
|
|
|
class SettingResource extends Resource
|
|
{
|
|
protected static ?string $model = Setting::class;
|
|
|
|
protected static ?string $navigationIcon = 'heroicon-o-cog';
|
|
|
|
protected static ?string $navigationGroup = 'Einstellungen';
|
|
|
|
public static function form(Form $form): Form
|
|
{
|
|
return $form
|
|
->schema([
|
|
Forms\Components\TextInput::make('key')
|
|
->label(__('Key'))
|
|
->required()
|
|
->maxLength(255)
|
|
->hiddenOn('edit'),
|
|
Forms\Components\Fieldset::make()
|
|
->label(fn (?Setting $record) => $record ? __('filament.resource.setting.form.' . $record->key) : __('New Setting'))
|
|
->schema([
|
|
TextInput::make('value')
|
|
->label(__('Bitte Wert eingeben'))
|
|
->disableLabel(fn (?Setting $record) => $record && ($record->key !== 'image_refresh_interval' && $record->key !== 'new_image_timespan_minutes' && $record->key !== 'gallery_heading'))
|
|
->formatStateUsing(function (?string $state, ?Setting $record) {
|
|
if ($record && $record->key === 'image_refresh_interval') {
|
|
return (int)$state / 1000;
|
|
} else if ($record && $record->key === 'new_image_timespan_minutes') {
|
|
return (int)$state;
|
|
}
|
|
return $state;
|
|
})
|
|
->dehydrateStateUsing(function (?string $state, ?Setting $record) {
|
|
if ($record && $record->key === 'image_refresh_interval') {
|
|
return (int)$state * 1000;
|
|
} else if ($record && $record->key === 'new_image_timespan_minutes') {
|
|
return (int)$state;
|
|
}
|
|
return $state;
|
|
})
|
|
])
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
Tables\Columns\TextColumn::make('key')->label(__('Key'))->searchable()->sortable(),
|
|
Tables\Columns\TextColumn::make('value')->label(__('Value'))->searchable()->sortable(),
|
|
])
|
|
->filters([
|
|
//
|
|
])
|
|
->actions([
|
|
Tables\Actions\EditAction::make(),
|
|
])
|
|
|
|
->bulkActions([
|
|
Tables\Actions\BulkActionGroup::make([
|
|
Tables\Actions\DeleteBulkAction::make(),
|
|
]),
|
|
])
|
|
->emptyStateActions([
|
|
Tables\Actions\CreateAction::make(),
|
|
]);
|
|
}
|
|
|
|
public static function getRelations(): array
|
|
{
|
|
return [
|
|
//
|
|
];
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => Pages\ListSettings::route('/'),
|
|
'create' => Pages\CreateSetting::route('/create'),
|
|
'edit' => Pages\EditSetting::route('/{record}/edit'),
|
|
];
|
|
}
|
|
}
|