Inhaltsverwaltung: Bilder, Webseiten-Texte, Ausstattung, FAQ, Hinweis-Banner
- Bilder mit automatischen WebP-Webgrößen (640/1280/2048 px), Sortierung per Drag & Drop, Mehrfach-Upload, Import-Befehl photos:import - Webseiten-Texte als feste, bearbeitbare Bausteine (config/content.php), Rich-Text bereinigt ausgegeben - Ausstattung und FAQ aus der bisherigen Webseite übernommen - Rolle Inhalte hat Zugriff auf alle Webseiten-Bereiche Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
27ea12901e
commit
bb7eb62782
53 files changed
+1963
-1
No files matched your search
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Enums\UserRole;
|
||||
use App\Models\Photo;
|
||||
use App\Support\Content;
|
||||
use BackedEnum;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\RichEditor;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Schemas\Components\Actions;
|
||||
use Filament\Schemas\Components\EmbeddedSchema;
|
||||
use Filament\Schemas\Components\Form;
|
||||
use Filament\Schemas\Components\Tabs;
|
||||
use Filament\Schemas\Components\Tabs\Tab;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use UnitEnum;
|
||||
|
||||
/**
|
||||
* One form for all editable website texts from config/content.php, one tab per section.
|
||||
*
|
||||
* @property-read Schema $form
|
||||
*/
|
||||
class EditContent extends Page
|
||||
{
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedPencilSquare;
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Webseite';
|
||||
|
||||
protected static ?string $navigationLabel = 'Texte';
|
||||
|
||||
protected static ?string $title = 'Webseiten-Texte';
|
||||
|
||||
protected static ?string $slug = 'texte';
|
||||
|
||||
protected static ?int $navigationSort = 2;
|
||||
|
||||
/** @var array<string, ?string> */
|
||||
public array $data = [];
|
||||
|
||||
public static function canAccess(): bool
|
||||
{
|
||||
return (bool) auth()->user()?->hasRole(UserRole::Admin, UserRole::Content);
|
||||
}
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$values = [];
|
||||
foreach (Content::sections() as $section) {
|
||||
foreach (array_keys($section['fields']) as $key) {
|
||||
$values[self::fieldName($key)] = Content::get($key);
|
||||
}
|
||||
}
|
||||
|
||||
$this->form->fill($values);
|
||||
}
|
||||
|
||||
public function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->statePath('data')
|
||||
->components([
|
||||
Tabs::make('sections')
|
||||
->persistTabInQueryString()
|
||||
->tabs(collect(Content::sections())
|
||||
->map(fn (array $section): Tab => Tab::make($section['label'])->schema(
|
||||
collect($section['fields'])->map(fn (array $field, string $key) => $this->field($key, $field))->values()->all(),
|
||||
))
|
||||
->values()
|
||||
->all()),
|
||||
]);
|
||||
}
|
||||
|
||||
public function content(Schema $schema): Schema
|
||||
{
|
||||
return $schema->components([
|
||||
Form::make([EmbeddedSchema::make('form')])
|
||||
->id('form')
|
||||
->livewireSubmitHandler('save')
|
||||
->footer([
|
||||
Actions::make([
|
||||
Action::make('save')->label('Speichern')->submit('save')->keyBindings(['mod+s']),
|
||||
])->sticky(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function save(): void
|
||||
{
|
||||
$state = $this->form->getState();
|
||||
|
||||
$values = [];
|
||||
foreach (Content::sections() as $section) {
|
||||
foreach (array_keys($section['fields']) as $key) {
|
||||
$value = $state[self::fieldName($key)] ?? null;
|
||||
$values[$key] = $value === null ? null : (string) $value;
|
||||
}
|
||||
}
|
||||
|
||||
Content::save($values);
|
||||
|
||||
Notification::make()->title('Texte gespeichert')->success()->send();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array{label: string, type: string, default?: ?string} $field
|
||||
*/
|
||||
private function field(string $key, array $field): TextInput|Textarea|RichEditor|Select
|
||||
{
|
||||
$name = self::fieldName($key);
|
||||
|
||||
return match ($field['type']) {
|
||||
'textarea' => Textarea::make($name)->label($field['label'])->rows(3),
|
||||
'richtext' => RichEditor::make($name)
|
||||
->label($field['label'])
|
||||
->toolbarButtons([['bold', 'italic', 'link'], ['h2', 'h3'], ['bulletList', 'orderedList'], ['undo', 'redo']]),
|
||||
'photo' => Select::make($name)
|
||||
->label($field['label'])
|
||||
->options(fn (): array => Photo::query()->orderBy('category')->orderBy('sort_order')->pluck('alt_text', 'id')->all())
|
||||
->searchable()
|
||||
->placeholder('Kein Bild gewählt')
|
||||
->helperText('Bilder verwalten Sie unter „Webseite › Bilder“.'),
|
||||
default => TextInput::make($name)->label($field['label'])->maxLength(255),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Dots would be read as nested state, so content keys are flattened for the form.
|
||||
*/
|
||||
private static function fieldName(string $key): string
|
||||
{
|
||||
return str_replace('.', '__', $key);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Amenities;
|
||||
|
||||
use App\Filament\Resources\Amenities\Pages\CreateAmenity;
|
||||
use App\Filament\Resources\Amenities\Pages\EditAmenity;
|
||||
use App\Filament\Resources\Amenities\Pages\ListAmenities;
|
||||
use App\Filament\Resources\Amenities\Schemas\AmenityForm;
|
||||
use App\Filament\Resources\Amenities\Tables\AmenitiesTable;
|
||||
use App\Models\Amenity;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
use UnitEnum;
|
||||
|
||||
class AmenityResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Amenity::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedListBullet;
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Webseite';
|
||||
|
||||
protected static ?string $modelLabel = 'Ausstattungsmerkmal';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Ausstattung';
|
||||
|
||||
protected static ?int $navigationSort = 3;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return AmenityForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return AmenitiesTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListAmenities::route('/'),
|
||||
'create' => CreateAmenity::route('/create'),
|
||||
'edit' => EditAmenity::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Amenities\Pages;
|
||||
|
||||
use App\Filament\Resources\Amenities\AmenityResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateAmenity extends CreateRecord
|
||||
{
|
||||
protected static string $resource = AmenityResource::class;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Amenities\Pages;
|
||||
|
||||
use App\Filament\Resources\Amenities\AmenityResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditAmenity extends EditRecord
|
||||
{
|
||||
protected static string $resource = AmenityResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Amenities\Pages;
|
||||
|
||||
use App\Filament\Resources\Amenities\AmenityResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListAmenities extends ListRecords
|
||||
{
|
||||
protected static string $resource = AmenityResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Amenities\Schemas;
|
||||
|
||||
use App\Enums\AmenityArea;
|
||||
use App\Models\Property;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class AmenityForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->columns(2)
|
||||
->components([
|
||||
TextInput::make('name')
|
||||
->label('Ausstattung')
|
||||
->placeholder('z. B. Geschirrspüler')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
Select::make('area')
|
||||
->label('Bereich')
|
||||
->options(AmenityArea::class)
|
||||
->required(),
|
||||
Select::make('property_id')
|
||||
->label('Wohnung')
|
||||
->options(fn (): array => Property::query()->pluck('name', 'id')->all())
|
||||
->default(fn (): ?int => Property::query()->value('id'))
|
||||
->required(),
|
||||
Toggle::make('is_highlight')
|
||||
->label('Highlight (auf der Startseite hervorheben)'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Amenities\Tables;
|
||||
|
||||
use App\Enums\AmenityArea;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Columns\ToggleColumn;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Grouping\Group;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class AmenitiesTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->reorderable('sort_order')
|
||||
->defaultSort('sort_order')
|
||||
->defaultGroup(Group::make('area')->label('Bereich')->getTitleFromRecordUsing(fn ($record): string => $record->area->getLabel()))
|
||||
->paginated(false)
|
||||
->columns([
|
||||
TextColumn::make('name')->label('Ausstattung')->searchable(),
|
||||
ToggleColumn::make('is_highlight')->label('Highlight'),
|
||||
])
|
||||
->filters([
|
||||
SelectFilter::make('area')->label('Bereich')->options(AmenityArea::class),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
DeleteAction::make(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Faqs;
|
||||
|
||||
use App\Filament\Resources\Faqs\Pages\CreateFaq;
|
||||
use App\Filament\Resources\Faqs\Pages\EditFaq;
|
||||
use App\Filament\Resources\Faqs\Pages\ListFaqs;
|
||||
use App\Filament\Resources\Faqs\Schemas\FaqForm;
|
||||
use App\Filament\Resources\Faqs\Tables\FaqsTable;
|
||||
use App\Models\Faq;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
use UnitEnum;
|
||||
|
||||
class FaqResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Faq::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedQuestionMarkCircle;
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Webseite';
|
||||
|
||||
protected static ?string $modelLabel = 'Frage';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Häufige Fragen';
|
||||
|
||||
protected static ?int $navigationSort = 4;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return FaqForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return FaqsTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListFaqs::route('/'),
|
||||
'create' => CreateFaq::route('/create'),
|
||||
'edit' => EditFaq::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Faqs\Pages;
|
||||
|
||||
use App\Filament\Resources\Faqs\FaqResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateFaq extends CreateRecord
|
||||
{
|
||||
protected static string $resource = FaqResource::class;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Faqs\Pages;
|
||||
|
||||
use App\Filament\Resources\Faqs\FaqResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditFaq extends EditRecord
|
||||
{
|
||||
protected static string $resource = FaqResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Faqs\Pages;
|
||||
|
||||
use App\Filament\Resources\Faqs\FaqResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListFaqs extends ListRecords
|
||||
{
|
||||
protected static string $resource = FaqResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Faqs\Schemas;
|
||||
|
||||
use Filament\Forms\Components\RichEditor;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class FaqForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
TextInput::make('question')
|
||||
->label('Frage')
|
||||
->required()
|
||||
->maxLength(255)
|
||||
->columnSpanFull(),
|
||||
RichEditor::make('answer')
|
||||
->label('Antwort')
|
||||
->toolbarButtons([['bold', 'italic', 'link'], ['bulletList', 'orderedList']])
|
||||
->required()
|
||||
->columnSpanFull(),
|
||||
Toggle::make('is_published')
|
||||
->label('Veröffentlicht')
|
||||
->default(true),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Faqs\Tables;
|
||||
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Columns\ToggleColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class FaqsTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->reorderable('sort_order')
|
||||
->defaultSort('sort_order')
|
||||
->paginated(false)
|
||||
->columns([
|
||||
TextColumn::make('question')->label('Frage')->searchable()->wrap(),
|
||||
ToggleColumn::make('is_published')->label('Veröffentlicht'),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
DeleteAction::make(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Notices;
|
||||
|
||||
use App\Filament\Resources\Notices\Pages\CreateNotice;
|
||||
use App\Filament\Resources\Notices\Pages\EditNotice;
|
||||
use App\Filament\Resources\Notices\Pages\ListNotices;
|
||||
use App\Filament\Resources\Notices\Schemas\NoticeForm;
|
||||
use App\Filament\Resources\Notices\Tables\NoticesTable;
|
||||
use App\Models\Notice;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
use UnitEnum;
|
||||
|
||||
class NoticeResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Notice::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedMegaphone;
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Webseite';
|
||||
|
||||
protected static ?string $modelLabel = 'Hinweis';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Hinweis-Banner';
|
||||
|
||||
protected static ?int $navigationSort = 5;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return NoticeForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return NoticesTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListNotices::route('/'),
|
||||
'create' => CreateNotice::route('/create'),
|
||||
'edit' => EditNotice::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Notices\Pages;
|
||||
|
||||
use App\Filament\Resources\Notices\NoticeResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateNotice extends CreateRecord
|
||||
{
|
||||
protected static string $resource = NoticeResource::class;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Notices\Pages;
|
||||
|
||||
use App\Filament\Resources\Notices\NoticeResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditNotice extends EditRecord
|
||||
{
|
||||
protected static string $resource = NoticeResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Notices\Pages;
|
||||
|
||||
use App\Filament\Resources\Notices\NoticeResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListNotices extends ListRecords
|
||||
{
|
||||
protected static string $resource = NoticeResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Notices\Schemas;
|
||||
|
||||
use App\Enums\NoticeTone;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class NoticeForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->columns(2)
|
||||
->components([
|
||||
TextInput::make('text')
|
||||
->label('Hinweistext')
|
||||
->placeholder('z. B. Kurzfristig frei: 12.–15.11. mit 15 % Rabatt')
|
||||
->required()
|
||||
->maxLength(255)
|
||||
->columnSpanFull(),
|
||||
Select::make('tone')
|
||||
->label('Art')
|
||||
->options(NoticeTone::class)
|
||||
->default(NoticeTone::Info)
|
||||
->required(),
|
||||
Toggle::make('is_active')
|
||||
->label('Aktiv')
|
||||
->default(true)
|
||||
->inline(false),
|
||||
DatePicker::make('starts_on')
|
||||
->label('Anzeigen ab (optional)'),
|
||||
DatePicker::make('ends_on')
|
||||
->label('Anzeigen bis (optional)')
|
||||
->afterOrEqual('starts_on'),
|
||||
TextInput::make('link_label')
|
||||
->label('Link-Text (optional)')
|
||||
->placeholder('z. B. Jetzt anfragen')
|
||||
->maxLength(100),
|
||||
TextInput::make('link_url')
|
||||
->label('Link-Ziel (optional)')
|
||||
->placeholder('/buchen')
|
||||
->maxLength(255),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Notices\Tables;
|
||||
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Columns\ToggleColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class NoticesTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->defaultSort('starts_on', 'desc')
|
||||
->columns([
|
||||
TextColumn::make('text')->label('Hinweis')->wrap()->searchable(),
|
||||
TextColumn::make('tone')->label('Art')->badge(),
|
||||
TextColumn::make('starts_on')->label('Ab')->date('d.m.Y')->placeholder('sofort'),
|
||||
TextColumn::make('ends_on')->label('Bis')->date('d.m.Y')->placeholder('unbegrenzt'),
|
||||
ToggleColumn::make('is_active')->label('Aktiv'),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
DeleteAction::make(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Photos\Pages;
|
||||
|
||||
use App\Filament\Resources\Photos\PhotoResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreatePhoto extends CreateRecord
|
||||
{
|
||||
protected static string $resource = PhotoResource::class;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Photos\Pages;
|
||||
|
||||
use App\Filament\Resources\Photos\PhotoResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditPhoto extends EditRecord
|
||||
{
|
||||
protected static string $resource = PhotoResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Photos\Pages;
|
||||
|
||||
use App\Enums\PhotoCategory;
|
||||
use App\Filament\Resources\Photos\PhotoResource;
|
||||
use App\Models\Photo;
|
||||
use App\Models\Property;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
|
||||
|
||||
class ListPhotos extends ListRecords
|
||||
{
|
||||
protected static string $resource = PhotoResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('bulkUpload')
|
||||
->label('Mehrere Bilder hochladen')
|
||||
->icon(Heroicon::OutlinedArrowUpTray)
|
||||
->authorize('create', Photo::class)
|
||||
->modalDescription('Die Bildbeschreibung wird aus dem Dateinamen vorbelegt – bitte danach kurz anpassen.')
|
||||
->schema([
|
||||
FileUpload::make('files')
|
||||
->label('Bilder')
|
||||
->multiple()
|
||||
->image()
|
||||
->maxSize(25 * 1024)
|
||||
->storeFiles(false)
|
||||
->required(),
|
||||
Select::make('category')
|
||||
->label('Kategorie')
|
||||
->options(PhotoCategory::class)
|
||||
->default(PhotoCategory::Apartment)
|
||||
->required(),
|
||||
])
|
||||
->action(function (array $data): void {
|
||||
$propertyId = Property::query()->value('id');
|
||||
$nextSort = (int) Photo::max('sort_order');
|
||||
|
||||
/** @var TemporaryUploadedFile $file */
|
||||
foreach ($data['files'] as $file) {
|
||||
$photo = Photo::create([
|
||||
'property_id' => $data['category'] === PhotoCategory::Area->value ? null : $propertyId,
|
||||
'category' => $data['category'],
|
||||
'alt_text' => str(pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME))->replace(['_', '-'], ' ')->squish()->ucfirst()->toString(),
|
||||
'sort_order' => ++$nextSort,
|
||||
]);
|
||||
$photo->addMedia($file->getRealPath())
|
||||
->usingFileName($file->getClientOriginalName())
|
||||
->toMediaCollection(Photo::COLLECTION);
|
||||
}
|
||||
|
||||
Notification::make()->title(count($data['files']).' Bilder hochgeladen')->success()->send();
|
||||
}),
|
||||
CreateAction::make()->label('Einzelnes Bild'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Photos;
|
||||
|
||||
use App\Filament\Resources\Photos\Pages\CreatePhoto;
|
||||
use App\Filament\Resources\Photos\Pages\EditPhoto;
|
||||
use App\Filament\Resources\Photos\Pages\ListPhotos;
|
||||
use App\Filament\Resources\Photos\Schemas\PhotoForm;
|
||||
use App\Filament\Resources\Photos\Tables\PhotosTable;
|
||||
use App\Models\Photo;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
use UnitEnum;
|
||||
|
||||
class PhotoResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Photo::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedPhoto;
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Webseite';
|
||||
|
||||
protected static ?string $modelLabel = 'Bild';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Bilder';
|
||||
|
||||
protected static ?int $navigationSort = 1;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return PhotoForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return PhotosTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListPhotos::route('/'),
|
||||
'create' => CreatePhoto::route('/create'),
|
||||
'edit' => EditPhoto::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Photos\Schemas;
|
||||
|
||||
use App\Enums\PhotoCategory;
|
||||
use App\Models\Photo;
|
||||
use App\Models\Property;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class PhotoForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->columns(2)
|
||||
->components([
|
||||
SpatieMediaLibraryFileUpload::make('image')
|
||||
->label('Bild')
|
||||
->collection(Photo::COLLECTION)
|
||||
->image()
|
||||
->imageEditor()
|
||||
->maxSize(25 * 1024)
|
||||
->helperText('JPG, PNG oder WebP bis 25 MB. Große Originale sind willkommen – Web-Größen werden automatisch erzeugt.')
|
||||
->required()
|
||||
->columnSpanFull(),
|
||||
TextInput::make('alt_text')
|
||||
->label('Bildbeschreibung')
|
||||
->helperText('Kurz beschreiben, was zu sehen ist – wichtig für Google und für blinde Besucher.')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
TextInput::make('caption')
|
||||
->label('Bildunterschrift (optional)')
|
||||
->maxLength(255),
|
||||
Select::make('category')
|
||||
->label('Kategorie')
|
||||
->options(PhotoCategory::class)
|
||||
->default(PhotoCategory::Apartment)
|
||||
->required(),
|
||||
Select::make('property_id')
|
||||
->label('Wohnung')
|
||||
->options(fn (): array => Property::query()->pluck('name', 'id')->all())
|
||||
->default(fn (): ?int => Property::query()->value('id'))
|
||||
->placeholder('– keine (z. B. Umgebung) –'),
|
||||
Toggle::make('is_published')
|
||||
->label('Auf der Webseite zeigen')
|
||||
->default(true),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Photos\Tables;
|
||||
|
||||
use App\Enums\PhotoCategory;
|
||||
use App\Models\Photo;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\Layout\Stack;
|
||||
use Filament\Tables\Columns\SpatieMediaLibraryImageColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class PhotosTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->reorderable('sort_order')
|
||||
->defaultSort('sort_order')
|
||||
->contentGrid(['md' => 3, 'xl' => 4])
|
||||
->paginated([24, 48, 'all'])
|
||||
->columns([
|
||||
Stack::make([
|
||||
SpatieMediaLibraryImageColumn::make('image')
|
||||
->collection(Photo::COLLECTION)
|
||||
->conversion('sm')
|
||||
->imageHeight(180)
|
||||
->extraImgAttributes(['class' => 'w-full object-cover rounded-lg']),
|
||||
TextColumn::make('alt_text')
|
||||
->weight('medium')
|
||||
->searchable(),
|
||||
TextColumn::make('category')
|
||||
->badge(),
|
||||
IconColumn::make('is_published')
|
||||
->boolean()
|
||||
->trueIcon('heroicon-o-eye')
|
||||
->falseIcon('heroicon-o-eye-slash'),
|
||||
])->space(2),
|
||||
])
|
||||
->filters([
|
||||
SelectFilter::make('category')
|
||||
->label('Kategorie')
|
||||
->options(PhotoCategory::class),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
DeleteAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user