webseite funktioniert, pay sdk, blog backend funktioniert
This commit is contained in:
217
app/Filament/Blog/Resources/CategoryResource.php
Normal file
217
app/Filament/Blog/Resources/CategoryResource.php
Normal file
@@ -0,0 +1,217 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Blog\Resources;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
use App\Filament\Blog\Resources\CategoryResource\Pages;
|
||||
use App\Filament\Blog\Traits\HasContentEditor;
|
||||
use App\Models\BlogCategory;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\MarkdownEditor;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
use Filament\Schemas\Components\Utilities\Set;
|
||||
use Filament\Infolists\Components\TextEntry;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Illuminate\Support\Str;
|
||||
use Filament\Schemas\Components\Tabs as SchemaTabs;
|
||||
use Filament\Schemas\Components\Tabs\Tab as SchemaTab;
|
||||
|
||||
class CategoryResource extends Resource
|
||||
{
|
||||
use HasContentEditor;
|
||||
|
||||
protected static ?string $model = BlogCategory::class;
|
||||
|
||||
protected static string | \BackedEnum | null $navigationIcon = 'heroicon-o-list-bullet';
|
||||
|
||||
protected static ?string $navigationLabel = 'Kategorien';
|
||||
|
||||
protected static ?string $pluralLabel = 'Kategorien';
|
||||
|
||||
protected static ?string $modelLabel = 'Kategorie';
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->schema([
|
||||
SchemaTabs::make('Übersetzungen')
|
||||
->tabs([
|
||||
SchemaTab::make('Deutsch')
|
||||
->schema([
|
||||
TextInput::make('name_de')
|
||||
->label('Name')
|
||||
->validationAttribute('name_de')
|
||||
->live()
|
||||
->afterStateUpdated(function (Get $get, Set $set, ?string $state) {
|
||||
if (($get('slug') ?? '') !== Str::slug($state)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$set('slug', Str::slug($state));
|
||||
}),
|
||||
MarkdownEditor::make('description_de')
|
||||
->label('Beschreibung')
|
||||
->validationAttribute('description_de'),
|
||||
]),
|
||||
SchemaTab::make('Englisch')
|
||||
->schema([
|
||||
TextInput::make('name_en')
|
||||
->label('Name'),
|
||||
MarkdownEditor::make('description_en')
|
||||
->label('Beschreibung'),
|
||||
]),
|
||||
]),
|
||||
TextInput::make('slug')
|
||||
->label('Slug')
|
||||
->required()
|
||||
->unique(BlogCategory::class, 'slug', ignoreRecord: true),
|
||||
Section::make('Sichtbarkeit')
|
||||
->schema([
|
||||
Toggle::make('is_visible')
|
||||
->label('Sichtbar für Gäste')
|
||||
->default(true),
|
||||
]),
|
||||
Section::make('Metadaten')
|
||||
->schema([
|
||||
TextEntry::make('created_at')
|
||||
->label('Erstellt am')
|
||||
->default('—')
|
||||
->state(fn (?BlogCategory $record) => $record?->created_at?->diffForHumans()),
|
||||
TextEntry::make('updated_at')
|
||||
->label('Zuletzt geändert')
|
||||
->default('—')
|
||||
->state(fn (?BlogCategory $record) => $record?->updated_at?->diffForHumans()),
|
||||
]),
|
||||
])
|
||||
->columns(3);
|
||||
}
|
||||
|
||||
public static function mutateFormDataBeforeFill(array $data): array
|
||||
{
|
||||
$nameJson = $data['name'] ?? '[]';
|
||||
$nameArray = json_decode($nameJson, true) ?: [];
|
||||
$data['name_de'] = $nameArray['de'] ?? '';
|
||||
$data['name_en'] = $nameArray['en'] ?? '';
|
||||
|
||||
$descJson = $data['description'] ?? '[]';
|
||||
$descArray = json_decode($descJson, true) ?: [];
|
||||
$data['description_de'] = $descArray['de'] ?? '';
|
||||
$data['description_en'] = $descArray['en'] ?? '';
|
||||
|
||||
\Illuminate\Support\Facades\Log::info('BeforeFill Description Extraction:', [
|
||||
'descJson' => $descJson,
|
||||
'descArray' => $descArray,
|
||||
'description_de' => $data['description_de'],
|
||||
'description_en' => $data['description_en'],
|
||||
]);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function mutateFormDataBeforeCreate(array $data): array
|
||||
{
|
||||
\Illuminate\Support\Facades\Log::info('mutateFormDataBeforeCreate Input Data:', ['data' => $data]);
|
||||
|
||||
$nameData = [
|
||||
'de' => $data['name_de'] ?? '',
|
||||
'en' => $data['name_en'] ?? '',
|
||||
];
|
||||
$data['name'] = json_encode($nameData);
|
||||
\Illuminate\Support\Facades\Log::info('mutateFormDataBeforeCreate Name JSON:', ['name' => $nameData]);
|
||||
|
||||
$descData = [
|
||||
'de' => $data['description_de'] ?? '',
|
||||
'en' => $data['description_en'] ?? '',
|
||||
];
|
||||
$data['description'] = json_encode($descData);
|
||||
\Illuminate\Support\Facades\Log::info('mutateFormDataBeforeCreate Description JSON:', ['description' => $descData]);
|
||||
|
||||
unset($data['name_de'], $data['name_en'], $data['description_de'], $data['description_en']);
|
||||
|
||||
\Illuminate\Support\Facades\Log::info('mutateFormDataBeforeCreate Final Data:', $data);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function mutateFormDataBeforeSave(array $data): array
|
||||
{
|
||||
$transformed = static::mutateFormDataBeforeCreate($data);
|
||||
|
||||
return $transformed;
|
||||
}
|
||||
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('name')
|
||||
->label('Name (DE)')
|
||||
->getStateUsing(fn ($record) => json_decode($record->name ?? '[]', true)['de'] ?? '—')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('slug')
|
||||
->label('Slug')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
IconColumn::make('is_visible')
|
||||
->label('Sichtbar')
|
||||
->boolean()
|
||||
->trueIcon('heroicon-o-check-circle')
|
||||
->falseIcon('heroicon-o-x-circle'),
|
||||
TextColumn::make('updated_at')
|
||||
->label('Zuletzt geändert')
|
||||
->date()
|
||||
->sortable(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListCategories::route('/'),
|
||||
'create' => Pages\CreateCategory::route('/create'),
|
||||
'edit' => Pages\EditCategory::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getEloquentQuery()
|
||||
->withoutGlobalScopes([
|
||||
SoftDeletingScope::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Blog\Resources\CategoryResource\Pages;
|
||||
|
||||
use App\Filament\Blog\Resources\CategoryResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateCategory extends CreateRecord
|
||||
{
|
||||
protected static string $resource = CategoryResource::class;
|
||||
|
||||
protected function getFormValidationRules(): array
|
||||
{
|
||||
return [
|
||||
'name_de' => 'required|string|max:255',
|
||||
'description_de' => 'nullable|string',
|
||||
'name_en' => 'nullable|string|max:255',
|
||||
'description_en' => 'nullable|string',
|
||||
'slug' => 'required|string|max:255|unique:blog_categories,slug',
|
||||
'is_visible' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
protected function store()
|
||||
{
|
||||
$state = $this->form->getState();
|
||||
$data = $state['data'] ?? $state;
|
||||
|
||||
$data = \App\Filament\Blog\Resources\CategoryResource::mutateFormDataBeforeCreate($data);
|
||||
|
||||
$this->record = static::getResource()::getModel()::create($data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Blog\Resources\CategoryResource\Pages;
|
||||
|
||||
use App\Filament\Blog\Resources\CategoryResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditCategory extends EditRecord
|
||||
{
|
||||
protected static string $resource = CategoryResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getFormValidationRules(): array
|
||||
{
|
||||
return [
|
||||
'name_de' => 'required|string|max:255',
|
||||
'description_de' => 'nullable|string',
|
||||
'name_en' => 'nullable|string|max:255',
|
||||
'description_en' => 'nullable|string',
|
||||
'slug' => 'required|string|max:255|unique:blog_categories,slug,' . $this->record->id,
|
||||
'is_visible' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
public function mount($record): void
|
||||
{
|
||||
parent::mount($record);
|
||||
$data = $this->record->toArray();
|
||||
$data = \App\Filament\Blog\Resources\CategoryResource::mutateFormDataBeforeFill($data);
|
||||
$this->form->fill($data);
|
||||
}
|
||||
|
||||
public function save(bool $shouldRedirect = true, bool $shouldSendSavedNotification = true): void
|
||||
{
|
||||
$state = $this->form->getState();
|
||||
\Illuminate\Support\Facades\Log::info('EditCategory Save - Full State:', $state);
|
||||
|
||||
$data = $state['data'] ?? $state;
|
||||
|
||||
$data = \App\Filament\Blog\Resources\CategoryResource::mutateFormDataBeforeSave($data);
|
||||
|
||||
$this->record->update($data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Blog\Resources\CategoryResource\Pages;
|
||||
|
||||
use App\Filament\Blog\Resources\CategoryResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListCategories extends ListRecords
|
||||
{
|
||||
protected static string $resource = CategoryResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
304
app/Filament/Blog/Resources/PostResource.php
Normal file
304
app/Filament/Blog/Resources/PostResource.php
Normal file
@@ -0,0 +1,304 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Blog\Resources;
|
||||
|
||||
use App\Filament\Blog\Resources\PostResource\Pages;
|
||||
use App\Filament\Blog\Traits\HasContentEditor;
|
||||
use App\Models\BlogPost;
|
||||
use App\Models\BlogCategory;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\MarkdownEditor;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
use Filament\Schemas\Components\Utilities\Set;
|
||||
use Filament\Infolists\Components\TextEntry;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Actions\ViewAction;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\TernaryFilter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Illuminate\Support\Str;
|
||||
use Filament\Schemas\Components\Tabs as SchemaTabs;
|
||||
use Filament\Schemas\Components\Tabs\Tab as SchemaTab;
|
||||
class PostResource extends Resource
|
||||
{
|
||||
use HasContentEditor;
|
||||
|
||||
protected static ?string $model = BlogPost::class;
|
||||
|
||||
protected static string | \BackedEnum | null $navigationIcon = 'heroicon-o-document-text';
|
||||
|
||||
protected static ?string $navigationLabel = 'Beiträge';
|
||||
|
||||
protected static ?string $pluralLabel = 'Beiträge';
|
||||
|
||||
protected static ?string $modelLabel = 'Beitrag';
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->schema([
|
||||
SchemaTabs::make('Übersetzungen')
|
||||
->tabs([
|
||||
SchemaTab::make('Deutsch')
|
||||
->schema([
|
||||
TextInput::make('title_de')
|
||||
->label('Titel')
|
||||
->required()
|
||||
->maxLength(255)
|
||||
->live()
|
||||
->afterStateUpdated(function (Get $get, Set $set, ?string $old, ?string $state) {
|
||||
if (($get('slug') ?? '') !== Str::slug($state)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$set('slug', Str::slug($state));
|
||||
}),
|
||||
MarkdownEditor::make('content_de')
|
||||
->label('Inhalt')
|
||||
->required()
|
||||
->columnSpanFull(),
|
||||
TextInput::make('excerpt_de')
|
||||
->label('Auszug')
|
||||
->maxLength(255),
|
||||
TextInput::make('meta_title_de')
|
||||
->label('Meta-Titel')
|
||||
->maxLength(255),
|
||||
Textarea::make('meta_description_de')
|
||||
->label('Meta-Beschreibung')
|
||||
->maxLength(65535)
|
||||
->columnSpanFull(),
|
||||
])
|
||||
->columns(2),
|
||||
SchemaTab::make('Englisch')
|
||||
->schema([
|
||||
TextInput::make('title_en')
|
||||
->label('Titel')
|
||||
->maxLength(255),
|
||||
MarkdownEditor::make('content_en')
|
||||
->label('Inhalt')
|
||||
->columnSpanFull(),
|
||||
TextInput::make('excerpt_en')
|
||||
->label('Auszug')
|
||||
->maxLength(255),
|
||||
TextInput::make('meta_title_en')
|
||||
->label('Meta-Titel')
|
||||
->maxLength(255),
|
||||
Textarea::make('meta_description_en')
|
||||
->label('Meta-Beschreibung')
|
||||
->maxLength(65535)
|
||||
->columnSpanFull(),
|
||||
])
|
||||
->columns(2),
|
||||
]),
|
||||
TextInput::make('slug')
|
||||
->label('Slug')
|
||||
->required()
|
||||
->unique(BlogPost::class, 'slug', ignoreRecord: true)
|
||||
->maxLength(255),
|
||||
Section::make('Bild und Kategorie')
|
||||
->schema([
|
||||
FileUpload::make('featured_image')
|
||||
->label('Featured Image')
|
||||
->image()
|
||||
->directory('blog')
|
||||
->visibility('public'),
|
||||
Select::make('category_id')
|
||||
->label('Kategorie')
|
||||
->relationship('category', 'name_de')
|
||||
->required()
|
||||
->preload()
|
||||
->createOptionForm([
|
||||
TextInput::make('name_de')
|
||||
->label('Name (DE)')
|
||||
->required()
|
||||
->maxLength(255)
|
||||
->afterStateUpdated(fn (Set $set, $state) => $set('name_en', $state)),
|
||||
TextInput::make('slug')
|
||||
->label('Slug')
|
||||
->required()
|
||||
->unique(\App\Models\BlogCategory::class, 'slug', ignoreRecord: true)
|
||||
->maxLength(255),
|
||||
]),
|
||||
])
|
||||
->columns(2),
|
||||
Section::make('Veröffentlichung')
|
||||
->schema([
|
||||
Toggle::make('is_published')
|
||||
->label('Veröffentlicht'),
|
||||
DateTimePicker::make('published_at')
|
||||
->label('Veröffentlicht am')
|
||||
->displayFormat('Y-m-d H:i:s')
|
||||
->default(now()),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function mutateFormDataBeforeCreate(array $data): array
|
||||
{
|
||||
$data['translations'] = [
|
||||
'title' => [
|
||||
'de' => $data['title_de'] ?? '',
|
||||
'en' => $data['title_en'] ?? '',
|
||||
],
|
||||
'content' => [
|
||||
'de' => $data['content_de'] ?? '',
|
||||
'en' => $data['content_en'] ?? '',
|
||||
],
|
||||
'excerpt' => [
|
||||
'de' => $data['excerpt_de'] ?? '',
|
||||
'en' => $data['excerpt_en'] ?? '',
|
||||
],
|
||||
'meta_title' => [
|
||||
'de' => $data['meta_title_de'] ?? '',
|
||||
'en' => $data['meta_title_en'] ?? '',
|
||||
],
|
||||
'meta_description' => [
|
||||
'de' => $data['meta_description_de'] ?? '',
|
||||
'en' => $data['meta_description_en'] ?? '',
|
||||
],
|
||||
];
|
||||
|
||||
unset($data['title_de'], $data['title_en'], $data['content_de'], $data['content_en'], $data['excerpt_de'], $data['excerpt_en'], $data['meta_title_de'], $data['meta_title_en'], $data['meta_description_de'], $data['meta_description_en']);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function mutateFormDataBeforeFill(array $data): array
|
||||
{
|
||||
$record = static::getModel()::find(request()?->route()?->parameter('record') ?? request()?->input('record_id') ?? null);
|
||||
|
||||
if (!$record) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
$data['title_de'] = $record->getTranslation('title', 'de');
|
||||
$data['title_en'] = $record->getTranslation('title', 'en');
|
||||
$data['content_de'] = $record->getTranslation('content', 'de');
|
||||
$data['content_en'] = $record->getTranslation('content', 'en');
|
||||
$data['excerpt_de'] = $record->getTranslation('excerpt', 'de');
|
||||
$data['excerpt_en'] = $record->getTranslation('excerpt', 'en');
|
||||
$data['meta_title_de'] = $record->getTranslation('meta_title', 'de');
|
||||
$data['meta_title_en'] = $record->getTranslation('meta_title', 'en');
|
||||
$data['meta_description_de'] = $record->getTranslation('meta_description', 'de');
|
||||
$data['meta_description_en'] = $record->getTranslation('meta_description', 'en');
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function mutateFormDataBeforeSave(array $data): array
|
||||
{
|
||||
$data['translations'] = [
|
||||
'title' => [
|
||||
'de' => $data['title_de'] ?? '',
|
||||
'en' => $data['title_en'] ?? '',
|
||||
],
|
||||
'content' => [
|
||||
'de' => $data['content_de'] ?? '',
|
||||
'en' => $data['content_en'] ?? '',
|
||||
],
|
||||
'excerpt' => [
|
||||
'de' => $data['excerpt_de'] ?? '',
|
||||
'en' => $data['excerpt_en'] ?? '',
|
||||
],
|
||||
'meta_title' => [
|
||||
'de' => $data['meta_title_de'] ?? '',
|
||||
'en' => $data['meta_title_en'] ?? '',
|
||||
],
|
||||
'meta_description' => [
|
||||
'de' => $data['meta_description_de'] ?? '',
|
||||
'en' => $data['meta_description_en'] ?? '',
|
||||
],
|
||||
];
|
||||
|
||||
unset($data['title_de'], $data['title_en'], $data['content_de'], $data['content_en'], $data['excerpt_de'], $data['excerpt_en'], $data['meta_title_de'], $data['meta_title_en'], $data['meta_description_de'], $data['meta_description_en']);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('title')
|
||||
->label('Titel (DE)')
|
||||
->getStateUsing(fn ($record) => $record->getTranslation('title', 'de'))
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('category.name_de')
|
||||
->label('Kategorie')
|
||||
->badge()
|
||||
->color('primary'),
|
||||
IconColumn::make('is_published')
|
||||
->label('Veröffentlicht')
|
||||
->boolean()
|
||||
->trueIcon('heroicon-o-check-circle')
|
||||
->falseIcon('heroicon-o-x-circle'),
|
||||
TextColumn::make('published_at')
|
||||
->label('Veröffentlicht am')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('created_at')
|
||||
->label('Erstellt am')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
TernaryFilter::make('is_published')
|
||||
->label('Veröffentlicht'),
|
||||
])
|
||||
->actions([
|
||||
ViewAction::make(),
|
||||
EditAction::make(),
|
||||
DeleteAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListPosts::route('/'),
|
||||
'create' => Pages\CreatePost::route('/create'),
|
||||
'view' => Pages\ViewPost::route('/{record}'),
|
||||
'edit' => Pages\EditPost::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getEloquentQuery()
|
||||
->withoutGlobalScopes([
|
||||
SoftDeletingScope::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Blog\Resources\PostResource\Pages;
|
||||
|
||||
use App\Filament\Blog\Resources\PostResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreatePost extends CreateRecord
|
||||
{
|
||||
protected static string $resource = PostResource::class;
|
||||
}
|
||||
20
app/Filament/Blog/Resources/PostResource/Pages/EditPost.php
Normal file
20
app/Filament/Blog/Resources/PostResource/Pages/EditPost.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Blog\Resources\PostResource\Pages;
|
||||
|
||||
use App\Filament\Blog\Resources\PostResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditPost extends EditRecord
|
||||
{
|
||||
protected static string $resource = PostResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\ViewAction::make(),
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
19
app/Filament/Blog/Resources/PostResource/Pages/ListPosts.php
Normal file
19
app/Filament/Blog/Resources/PostResource/Pages/ListPosts.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Blog\Resources\PostResource\Pages;
|
||||
|
||||
use App\Filament\Blog\Resources\PostResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListPosts extends ListRecords
|
||||
{
|
||||
protected static string $resource = PostResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
11
app/Filament/Blog/Resources/PostResource/Pages/ViewPost.php
Normal file
11
app/Filament/Blog/Resources/PostResource/Pages/ViewPost.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Blog\Resources\PostResource\Pages;
|
||||
|
||||
use App\Filament\Blog\Resources\PostResource;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
|
||||
class ViewPost extends ViewRecord
|
||||
{
|
||||
protected static string $resource = PostResource::class;
|
||||
}
|
||||
29
app/Filament/Blog/Traits/HasContentEditor.php
Normal file
29
app/Filament/Blog/Traits/HasContentEditor.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Blog\Traits;
|
||||
|
||||
use Filament\Forms\Components\MarkdownEditor;
|
||||
|
||||
trait HasContentEditor
|
||||
{
|
||||
public static function getContentEditor(string $field)
|
||||
{
|
||||
return MarkdownEditor::make($field)
|
||||
->label('Inhalt')
|
||||
->columnSpanFull()
|
||||
->toolbarButtons(config('filament-blog.toolbar_buttons', [
|
||||
'bold',
|
||||
'italic',
|
||||
'underline',
|
||||
'strike',
|
||||
'bulletList',
|
||||
'orderedList',
|
||||
'link',
|
||||
'table',
|
||||
'codeBlock',
|
||||
'h1',
|
||||
'h2',
|
||||
'h3',
|
||||
]));
|
||||
}
|
||||
}
|
||||
@@ -93,6 +93,135 @@ class PackageResource extends Resource
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public static function featuresToRepeaterItems(mixed $features): array
|
||||
{
|
||||
if (is_string($features)) {
|
||||
$decoded = json_decode($features, true);
|
||||
|
||||
if (is_string($decoded)) {
|
||||
$decoded = json_decode($decoded, true);
|
||||
}
|
||||
|
||||
$features = json_last_error() === JSON_ERROR_NONE ? $decoded : null;
|
||||
}
|
||||
|
||||
if ($features === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (! is_array($features)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (! array_is_list($features)) {
|
||||
return collect($features)
|
||||
->map(function ($value, $key) {
|
||||
return [
|
||||
'key' => (string) $key,
|
||||
'value' => is_bool($value) ? ($value ? 'true' : 'false') : (string) $value,
|
||||
];
|
||||
})
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
|
||||
return collect($features)
|
||||
->map(function ($item) {
|
||||
if (is_array($item)) {
|
||||
return [
|
||||
'key' => (string) ($item['key'] ?? ''),
|
||||
'value' => (string) ($item['value'] ?? ''),
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'key' => (string) $item,
|
||||
'value' => 'true',
|
||||
];
|
||||
})
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
|
||||
public static function featuresFromRepeaterItems(mixed $items): array
|
||||
{
|
||||
if (! is_array($items)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$features = [];
|
||||
|
||||
foreach ($items as $item) {
|
||||
if (! is_array($item)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$key = isset($item['key']) ? trim((string) $item['key']) : '';
|
||||
|
||||
if ($key === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$value = $item['value'] ?? true;
|
||||
|
||||
if (is_string($value)) {
|
||||
$normalized = strtolower(trim($value));
|
||||
|
||||
if (in_array($normalized, ['1', 'true', 'yes', 'on'], true)) {
|
||||
$value = true;
|
||||
} elseif (in_array($normalized, ['0', 'false', 'no', 'off'], true)) {
|
||||
$value = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_array($value)) {
|
||||
$value = $value['value'] ?? $value['enabled'] ?? true;
|
||||
}
|
||||
|
||||
$features[$key] = (bool) $value;
|
||||
}
|
||||
|
||||
return $features;
|
||||
}
|
||||
|
||||
public static function formatFeaturesForDisplay(mixed $features): string
|
||||
{
|
||||
$map = $features;
|
||||
|
||||
if (! is_array($map)) {
|
||||
if (is_string($map)) {
|
||||
$decoded = json_decode($map, true);
|
||||
|
||||
if (is_string($decoded)) {
|
||||
$decoded = json_decode($decoded, true);
|
||||
}
|
||||
|
||||
$map = json_last_error() === JSON_ERROR_NONE ? $decoded : [];
|
||||
} else {
|
||||
$map = [];
|
||||
}
|
||||
}
|
||||
|
||||
if (! array_is_list($map)) {
|
||||
return collect($map)
|
||||
->filter(fn ($value) => (bool) $value)
|
||||
->keys()
|
||||
->implode(', ');
|
||||
}
|
||||
|
||||
return collect($map)
|
||||
->map(function ($item) {
|
||||
if (is_array($item)) {
|
||||
return (string) ($item['key'] ?? '');
|
||||
}
|
||||
|
||||
return (string) $item;
|
||||
})
|
||||
->filter()
|
||||
->implode(', ');
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
@@ -119,6 +248,7 @@ class PackageResource extends Resource
|
||||
->color('primary'),
|
||||
TextColumn::make('features')
|
||||
->label('Features')
|
||||
->formatStateUsing(fn ($state) => static::formatFeaturesForDisplay($state))
|
||||
->limit(50),
|
||||
])
|
||||
->filters([
|
||||
@@ -150,4 +280,4 @@ class PackageResource extends Resource
|
||||
'edit' => Pages\EditPackage::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,4 +8,12 @@ use Filament\Resources\Pages\CreateRecord;
|
||||
class CreatePackage extends CreateRecord
|
||||
{
|
||||
protected static string $resource = PackageResource::class;
|
||||
}
|
||||
|
||||
protected function mutateFormDataBeforeCreate(array $data): array
|
||||
{
|
||||
$data['features'] = PackageResource::featuresFromRepeaterItems($data['features'] ?? []);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,4 +17,19 @@ class EditPackage extends EditRecord
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
protected function mutateFormDataBeforeFill(array $data): array
|
||||
{
|
||||
$data['features'] = PackageResource::featuresToRepeaterItems($data['features'] ?? null);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function mutateFormDataBeforeSave(array $data): array
|
||||
{
|
||||
$data['features'] = PackageResource::featuresFromRepeaterItems($data['features'] ?? []);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,12 +12,12 @@ use Filament\Forms\Components\Toggle;
|
||||
use Filament\Icons\Icon;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Actions\ActionGroup;
|
||||
use Filament\Tables\Actions\BulkActionGroup;
|
||||
use Filament\Tables\Actions\CreateAction;
|
||||
use Filament\Tables\Actions\DeleteAction;
|
||||
use Filament\Tables\Actions\EditAction;
|
||||
use Filament\Tables\Actions\ViewAction;
|
||||
use Filament\Actions\ActionGroup;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Actions\ViewAction;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
@@ -38,8 +38,7 @@ class TenantResource extends Resource
|
||||
|
||||
public static function form(Schema $form): Schema
|
||||
{
|
||||
\Illuminate\Support\Facades\Log::info('TenantResource form() method called');
|
||||
|
||||
|
||||
return $form->schema([
|
||||
TextInput::make('name')
|
||||
->label(__('admin.tenants.fields.name'))
|
||||
@@ -87,8 +86,7 @@ class TenantResource extends Resource
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
\Illuminate\Support\Facades\Log::info('TenantResource table() method called');
|
||||
|
||||
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('id')->sortable(),
|
||||
@@ -183,8 +181,7 @@ class TenantResource extends Resource
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
\Illuminate\Support\Facades\Log::info('TenantResource getRelations() method called');
|
||||
|
||||
|
||||
return [
|
||||
TenantPackagesRelationManager::class,
|
||||
PackagePurchasesRelationManager::class,
|
||||
|
||||
@@ -10,9 +10,9 @@ use Filament\Forms\Components\Textarea;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Actions\BulkActionGroup;
|
||||
use Filament\Tables\Actions\DeleteBulkAction;
|
||||
use Filament\Tables\Actions\ViewAction;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\ViewAction;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
@@ -140,4 +140,5 @@ class PackagePurchasesRelationManager extends RelationManager
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,9 +10,9 @@ use Filament\Forms\Components\Textarea;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Actions\BulkActionGroup;
|
||||
use Filament\Tables\Actions\DeleteBulkAction;
|
||||
use Filament\Tables\Actions\ViewAction;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\ViewAction;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Table;
|
||||
@@ -128,3 +128,5 @@ class PurchasesRelationManager extends RelationManager
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -12,11 +12,11 @@ use Filament\Forms\Components\Textarea;
|
||||
use Filament\Icons\Icon;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Actions\ActionGroup;
|
||||
use Filament\Tables\Actions\BulkActionGroup;
|
||||
use Filament\Tables\Actions\DeleteBulkAction;
|
||||
use Filament\Tables\Actions\EditAction;
|
||||
use Filament\Tables\Actions\ViewAction;
|
||||
use Filament\Actions\ActionGroup;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Actions\ViewAction;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
@@ -129,4 +129,5 @@ class UserResource extends Resource
|
||||
'edit' => Pages\EditUser::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,15 +10,14 @@ use Stripe\Stripe;
|
||||
use Stripe\Checkout\Session;
|
||||
use Stripe\StripeClient;
|
||||
use Exception;
|
||||
use PayPal\Api\Amount;
|
||||
use PayPal\Api\Payer;
|
||||
use PayPal\Api\Payment;
|
||||
use PayPal\Api\RedirectUrls;
|
||||
use PayPal\Api\Transaction;
|
||||
use PayPal\Rest\ApiContext;
|
||||
use PayPal\Auth\OAuthTokenCredential;
|
||||
use PayPal\PayPalHttp\Client;
|
||||
use PayPal\PayPalHttp\HttpException;
|
||||
use PayPal\Checkout\Orders\OrdersCreateRequest;
|
||||
use PayPal\Checkout\Orders\OrdersCaptureRequest;
|
||||
use PayPal\Checkout\Orders\OrdersGetRequest;
|
||||
use PayPal\Checkout\Orders\Order;
|
||||
use App\Models\Tenant;
|
||||
use App\Models\EventPurchase;
|
||||
use App\Models\BlogPost;
|
||||
use App\Models\Package;
|
||||
use App\Models\TenantPackage;
|
||||
use App\Models\PackagePurchase;
|
||||
@@ -107,6 +106,10 @@ class MarketingController extends Controller
|
||||
return redirect('/admin')->with('success', __('marketing.packages.free_assigned'));
|
||||
}
|
||||
|
||||
if ($package->type === 'reseller') {
|
||||
return $this->stripeSubscription($request, $packageId);
|
||||
}
|
||||
|
||||
if ($request->input('provider') === 'paypal') {
|
||||
return $this->paypalCheckout($request, $packageId);
|
||||
}
|
||||
@@ -151,7 +154,7 @@ class MarketingController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* PayPal checkout with auth metadata.
|
||||
* PayPal checkout with v2 Orders API (one-time payment).
|
||||
*/
|
||||
public function paypalCheckout(Request $request, $packageId)
|
||||
{
|
||||
@@ -159,78 +162,228 @@ class MarketingController extends Controller
|
||||
$user = Auth::user();
|
||||
$tenant = $user->tenant;
|
||||
|
||||
$apiContext = new ApiContext(
|
||||
new OAuthTokenCredential(
|
||||
config('services.paypal.client_id'),
|
||||
config('services.paypal.secret')
|
||||
)
|
||||
);
|
||||
$client = Client::create([
|
||||
'clientId' => config('services.paypal.client_id'),
|
||||
'clientSecret' => config('services.paypal.secret'),
|
||||
'environment' => config('services.paypal.sandbox', true) ? 'sandbox' : 'live',
|
||||
]);
|
||||
|
||||
$payment = new Payment();
|
||||
$payer = new Payer();
|
||||
$payer->setPaymentMethod('paypal');
|
||||
$ordersController = $client->orders();
|
||||
|
||||
$amountObj = new Amount();
|
||||
$amountObj->setCurrency('EUR');
|
||||
$amountObj->setTotal($package->price);
|
||||
|
||||
$transaction = new Transaction();
|
||||
$transaction->setAmount($amountObj);
|
||||
|
||||
$redirectUrls = new RedirectUrls();
|
||||
$redirectUrls->setReturnUrl(route('marketing.success', $packageId));
|
||||
$redirectUrls->setCancelUrl(route('packages'));
|
||||
|
||||
$customData = json_encode([
|
||||
$metadata = json_encode([
|
||||
'user_id' => $user->id,
|
||||
'tenant_id' => $tenant->id,
|
||||
'package_id' => $package->id,
|
||||
'type' => $package->type,
|
||||
]);
|
||||
|
||||
$payment->setIntent('sale')
|
||||
->setPayer($payer)
|
||||
->setTransactions([$transaction])
|
||||
->setRedirectUrls($redirectUrls)
|
||||
->setNoteToPayer('Package: ' . $package->name)
|
||||
->setCustom($customData);
|
||||
$createRequest = new OrdersCreateRequest();
|
||||
$createRequest->prefer('return=representation');
|
||||
$createRequest->body = [
|
||||
"intent" => "CAPTURE",
|
||||
"purchase_units" => [[
|
||||
"amount" => [
|
||||
"currency_code" => "EUR",
|
||||
"value" => number_format($package->price, 2, '.', ''),
|
||||
],
|
||||
"description" => "Package: " . $package->name,
|
||||
"custom_id" => $metadata,
|
||||
]],
|
||||
"application_context" => [
|
||||
"return_url" => route('marketing.success', $packageId),
|
||||
"cancel_url" => route('packages'),
|
||||
],
|
||||
];
|
||||
|
||||
try {
|
||||
$payment->create($apiContext);
|
||||
$response = $ordersController->createOrder($createRequest);
|
||||
$order = $response->result;
|
||||
|
||||
session(['paypal_payment_id' => $payment->getId()]);
|
||||
session(['paypal_order_id' => $order->id]);
|
||||
|
||||
return redirect($payment->getApprovalLink());
|
||||
foreach ($order->links as $link) {
|
||||
if ($link->rel === 'approve') {
|
||||
return redirect($link->href);
|
||||
}
|
||||
}
|
||||
|
||||
throw new Exception('No approve link found');
|
||||
} catch (HttpException $e) {
|
||||
Log::error('PayPal Orders API error: ' . $e->getMessage());
|
||||
return back()->with('error', 'Zahlung fehlgeschlagen');
|
||||
} catch (\Exception $e) {
|
||||
Log::error('PayPal checkout error: ' . $e->getMessage());
|
||||
return back()->with('error', 'Zahlung fehlgeschlagen');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stripe subscription checkout for reseller packages.
|
||||
*/
|
||||
public function stripeSubscription(Request $request, $packageId)
|
||||
{
|
||||
$package = Package::findOrFail($packageId);
|
||||
$user = Auth::user();
|
||||
$tenant = $user->tenant;
|
||||
|
||||
$stripe = new StripeClient(config('services.stripe.secret'));
|
||||
$session = $stripe->checkout->sessions->create([
|
||||
'payment_method_types' => ['card'],
|
||||
'line_items' => [[
|
||||
'price_data' => [
|
||||
'currency' => 'eur',
|
||||
'product_data' => [
|
||||
'name' => $package->name . ' (Annual Subscription)',
|
||||
],
|
||||
'unit_amount' => $package->price * 100,
|
||||
'recurring' => [
|
||||
'interval' => 'year',
|
||||
'interval_count' => 1,
|
||||
],
|
||||
],
|
||||
'quantity' => 1,
|
||||
]],
|
||||
'mode' => 'subscription',
|
||||
'success_url' => route('marketing.success', $packageId),
|
||||
'cancel_url' => route('packages'),
|
||||
'metadata' => [
|
||||
'user_id' => $user->id,
|
||||
'tenant_id' => $tenant->id,
|
||||
'package_id' => $package->id,
|
||||
'type' => $package->type,
|
||||
'subscription' => 'true',
|
||||
],
|
||||
]);
|
||||
|
||||
return redirect($session->url, 303);
|
||||
}
|
||||
|
||||
public function stripeCheckout($sessionId)
|
||||
{
|
||||
// Handle Stripe success
|
||||
return view('marketing.success', ['provider' => 'Stripe']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle success after payment (capture PayPal, redirect if verified).
|
||||
*/
|
||||
public function success(Request $request, $packageId = null)
|
||||
{
|
||||
if (session('paypal_order_id')) {
|
||||
$orderId = session('paypal_order_id');
|
||||
$client = Client::create([
|
||||
'clientId' => config('services.paypal.client_id'),
|
||||
'clientSecret' => config('services.paypal.secret'),
|
||||
'environment' => config('services.paypal.sandbox', true) ? 'sandbox' : 'live',
|
||||
]);
|
||||
|
||||
$ordersController = $client->orders();
|
||||
|
||||
$captureRequest = new OrdersCaptureRequest($orderId);
|
||||
$captureRequest->prefer('return=minimal');
|
||||
|
||||
try {
|
||||
$captureResponse = $ordersController->captureOrder($captureRequest);
|
||||
$capture = $captureResponse->result;
|
||||
|
||||
if ($capture->status === 'COMPLETED') {
|
||||
$customId = $capture->purchaseUnits[0]->customId ?? null;
|
||||
if ($customId) {
|
||||
$metadata = json_decode($customId, true);
|
||||
$package = Package::find($metadata['package_id']);
|
||||
$tenant = Tenant::find($metadata['tenant_id']);
|
||||
|
||||
if ($package && $tenant) {
|
||||
TenantPackage::updateOrCreate(
|
||||
[
|
||||
'tenant_id' => $tenant->id,
|
||||
'package_id' => $package->id,
|
||||
],
|
||||
[
|
||||
'active' => true,
|
||||
'purchased_at' => now(),
|
||||
'expires_at' => now()->addYear(), // One-time as annual for reseller too
|
||||
]
|
||||
);
|
||||
|
||||
PackagePurchase::create([
|
||||
'tenant_id' => $tenant->id,
|
||||
'package_id' => $package->id,
|
||||
'provider_id' => 'paypal',
|
||||
'price' => $package->price,
|
||||
'type' => $package->type,
|
||||
'purchased_at' => now(),
|
||||
'refunded' => false,
|
||||
]);
|
||||
|
||||
session()->forget('paypal_order_id');
|
||||
$request->session()->flash('success', __('marketing.packages.purchased_successfully', ['name' => $package->name]));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Log::error('PayPal capture failed: ' . $capture->status);
|
||||
$request->session()->flash('error', 'Zahlung konnte nicht abgeschlossen werden.');
|
||||
}
|
||||
} catch (HttpException $e) {
|
||||
Log::error('PayPal capture error: ' . $e->getMessage());
|
||||
$request->session()->flash('error', 'Zahlung konnte nicht abgeschlossen werden.');
|
||||
} catch (\Exception $e) {
|
||||
Log::error('PayPal success error: ' . $e->getMessage());
|
||||
$request->session()->flash('error', 'Fehler beim Abschließen der Zahlung.');
|
||||
}
|
||||
}
|
||||
|
||||
// Common logic: Redirect to admin if verified
|
||||
if (Auth::check() && Auth::user()->email_verified_at) {
|
||||
return redirect('/admin')->with('success', __('marketing.success.welcome'));
|
||||
}
|
||||
|
||||
return view('marketing.success', compact('packageId'));
|
||||
}
|
||||
|
||||
public function blogIndex(Request $request)
|
||||
{
|
||||
$locale = $request->get('locale', app()->getLocale());
|
||||
$posts = \Stephenjude\FilamentBlog\Models\Post::query()
|
||||
->where('is_published', true)
|
||||
Log::info('Blog Index Debug - Initial', [
|
||||
'locale' => $locale,
|
||||
'full_url' => $request->fullUrl()
|
||||
]);
|
||||
|
||||
$query = BlogPost::query()
|
||||
->whereHas('category', function ($query) {
|
||||
$query->where('slug', 'blog');
|
||||
});
|
||||
|
||||
$totalWithCategory = $query->count();
|
||||
Log::info('Blog Index Debug - With Category', ['count' => $totalWithCategory]);
|
||||
|
||||
$query->where('is_published', true)
|
||||
->whereNotNull('published_at')
|
||||
->where('published_at', '<=', now())
|
||||
->whereJsonContains("translations->locale->title->{$locale}", true)
|
||||
->orderBy('published_at', 'desc')
|
||||
->where('published_at', '<=', now());
|
||||
|
||||
$totalPublished = $query->count();
|
||||
Log::info('Blog Index Debug - Published', ['count' => $totalPublished]);
|
||||
|
||||
$query->whereJsonContains("translations->locale->title->{$locale}", true);
|
||||
|
||||
$totalWithTranslation = $query->count();
|
||||
Log::info('Blog Index Debug - With Translation', ['count' => $totalWithTranslation, 'locale' => $locale]);
|
||||
|
||||
$posts = $query->orderBy('published_at', 'desc')
|
||||
->paginate(8);
|
||||
|
||||
Log::info('Blog Index Debug - Final Posts', ['count' => $posts->count(), 'total' => $posts->total()]);
|
||||
|
||||
return view('marketing.blog', compact('posts'));
|
||||
}
|
||||
|
||||
public function blogShow($slug)
|
||||
{
|
||||
$locale = app()->getLocale();
|
||||
$post = \Stephenjude\FilamentBlog\Models\Post::query()
|
||||
$post = BlogPost::query()
|
||||
->whereHas('category', function ($query) {
|
||||
$query->where('slug', 'blog');
|
||||
})
|
||||
->where('slug', $slug)
|
||||
->where('is_published', true)
|
||||
->whereNotNull('published_at')
|
||||
@@ -240,4 +393,24 @@ class MarketingController extends Controller
|
||||
|
||||
return view('marketing.blog-show', compact('post'));
|
||||
}
|
||||
|
||||
public function packagesIndex()
|
||||
{
|
||||
|
||||
$endcustomerPackages = Package::where('type', 'endcustomer')->orderBy('price')->get();
|
||||
$resellerPackages = Package::where('type', 'reseller')->orderBy('price')->get();
|
||||
|
||||
return view('marketing.packages', compact('endcustomerPackages', 'resellerPackages'));
|
||||
}
|
||||
|
||||
public function occasionsType($locale, $type)
|
||||
{
|
||||
|
||||
$validTypes = ['weddings', 'birthdays', 'corporate-events', 'family-celebrations'];
|
||||
if (!in_array($type, $validTypes)) {
|
||||
abort(404, 'Invalid occasion type');
|
||||
}
|
||||
|
||||
return view('marketing.occasions', ['type' => $type]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,13 @@ namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Models\EventPurchase;
|
||||
use PayPal\PayPalHttp\Client;
|
||||
use PayPal\Checkout\Orders\OrdersGetRequest;
|
||||
use App\Models\TenantPackage;
|
||||
use App\Models\PackagePurchase;
|
||||
use App\Models\Package;
|
||||
use App\Models\Tenant;
|
||||
use Exception;
|
||||
|
||||
class PayPalWebhookController extends Controller
|
||||
{
|
||||
@@ -13,72 +18,114 @@ class PayPalWebhookController extends Controller
|
||||
{
|
||||
$input = $request->all();
|
||||
$ipnMessage = $input['ipn_track_id'] ?? null;
|
||||
$payerEmail = $input['payer_email'] ?? null;
|
||||
$paymentStatus = $input['payment_status'] ?? null;
|
||||
$mcGross = $input['mc_gross'] ?? 0;
|
||||
$custom = $input['custom'] ?? null;
|
||||
$verification = $this->verifyIPN($request);
|
||||
|
||||
if ($paymentStatus === 'Completed' && $mcGross > 0) {
|
||||
// Verify IPN with PayPal (simplified; use SDK for full verification)
|
||||
// $verified = $this->verifyIPN($input);
|
||||
if (!$verification) {
|
||||
Log::warning('PayPal IPN verification failed', ['ipn_track_id' => $ipnMessage]);
|
||||
return response('Invalid IPN', 400);
|
||||
}
|
||||
|
||||
// Parse custom for user_id or tenant_id
|
||||
$data = json_decode($custom, true);
|
||||
$userId = $data['user_id'] ?? null;
|
||||
$tenantId = $data['tenant_id'] ?? null;
|
||||
$packageId = $data['package_id'] ?? null;
|
||||
$eventType = $input['payment_status'] ?? null;
|
||||
$customId = $input['custom'] ?? null;
|
||||
|
||||
if ($userId && !$tenantId) {
|
||||
$tenant = \App\Models\Tenant::where('user_id', $userId)->first();
|
||||
if ($tenant) {
|
||||
$tenantId = $tenant->id;
|
||||
} else {
|
||||
Log::error('Tenant not found for user_id in PayPal IPN: ' . $userId);
|
||||
return response('OK', 200);
|
||||
}
|
||||
if (!$eventType || !$customId) {
|
||||
Log::warning('Missing event type or custom ID in PayPal IPN', ['input' => $input]);
|
||||
return response('Invalid data', 400);
|
||||
}
|
||||
|
||||
if ($eventType !== 'Completed') {
|
||||
Log::info('Non-completed PayPal event ignored', ['event' => $eventType, 'ipn_track_id' => $ipnMessage]);
|
||||
return response('OK', 200);
|
||||
}
|
||||
|
||||
try {
|
||||
$metadata = json_decode($customId, true);
|
||||
if (!$metadata || !isset($metadata['tenant_id'], $metadata['package_id'])) {
|
||||
throw new Exception('Invalid metadata');
|
||||
}
|
||||
|
||||
if (!$tenantId || !$packageId) {
|
||||
Log::error('Missing tenant or package in PayPal IPN custom data');
|
||||
$tenant = Tenant::find($metadata['tenant_id']);
|
||||
$package = Package::find($metadata['package_id']);
|
||||
|
||||
if (!$tenant || !$package) {
|
||||
throw new Exception('Tenant or package not found');
|
||||
}
|
||||
|
||||
// Idempotent: Check if already processed
|
||||
$existingPurchase = PackagePurchase::where('tenant_id', $tenant->id)
|
||||
->where('package_id', $package->id)
|
||||
->where('provider_id', 'paypal')
|
||||
->where('purchased_at', '>=', now()->subDay()) // Recent to avoid duplicates
|
||||
->first();
|
||||
|
||||
if ($existingPurchase) {
|
||||
Log::info('PayPal purchase already processed', ['purchase_id' => $existingPurchase->id]);
|
||||
return response('OK', 200);
|
||||
}
|
||||
|
||||
// Create PackagePurchase
|
||||
\App\Models\PackagePurchase::create([
|
||||
'tenant_id' => $tenantId,
|
||||
'package_id' => $packageId,
|
||||
'provider_id' => $ipnMessage,
|
||||
'price' => $mcGross,
|
||||
'type' => $data['type'] ?? 'reseller_subscription',
|
||||
// Activate package
|
||||
TenantPackage::updateOrCreate(
|
||||
[
|
||||
'tenant_id' => $tenant->id,
|
||||
'package_id' => $package->id,
|
||||
],
|
||||
[
|
||||
'active' => true,
|
||||
'purchased_at' => now(),
|
||||
'expires_at' => now()->addYear(),
|
||||
]
|
||||
);
|
||||
|
||||
// Log purchase
|
||||
PackagePurchase::create([
|
||||
'tenant_id' => $tenant->id,
|
||||
'package_id' => $package->id,
|
||||
'provider_id' => 'paypal',
|
||||
'price' => $package->price,
|
||||
'type' => $package->type,
|
||||
'purchased_at' => now(),
|
||||
'refunded' => false,
|
||||
]);
|
||||
|
||||
// Update TenantPackage if subscription
|
||||
if ($data['type'] ?? '' === 'reseller_subscription') {
|
||||
\App\Models\TenantPackage::updateOrCreate(
|
||||
[
|
||||
'tenant_id' => $tenantId,
|
||||
'package_id' => $packageId,
|
||||
],
|
||||
[
|
||||
'active' => true,
|
||||
'purchased_at' => now(),
|
||||
'expires_at' => now()->addYear(),
|
||||
]
|
||||
);
|
||||
}
|
||||
$tenant->update(['subscription_status' => 'active']);
|
||||
|
||||
Log::info('PayPal IPN processed for tenant ' . $tenantId . ', package ' . $packageId, $input);
|
||||
Log::info('PayPal purchase processed successfully', [
|
||||
'tenant_id' => $tenant->id,
|
||||
'package_id' => $package->id,
|
||||
'ipn_track_id' => $ipnMessage,
|
||||
]);
|
||||
|
||||
return response('OK', 200);
|
||||
} catch (Exception $e) {
|
||||
Log::error('PayPal webhook processing error: ' . $e->getMessage(), [
|
||||
'input' => $input,
|
||||
'ipn_track_id' => $ipnMessage,
|
||||
]);
|
||||
return response('Error', 500);
|
||||
}
|
||||
}
|
||||
|
||||
private function verifyIPN(Request $request)
|
||||
{
|
||||
$rawBody = $request->getContent();
|
||||
$params = $request->all();
|
||||
|
||||
// For sandbox, post to PayPal verify endpoint
|
||||
$verifyParams = array_merge($params, ['cmd' => '_notify-validate']);
|
||||
|
||||
$response = file_get_contents('https://ipnpb.paypal.com/cgi-bin/webscr', false, stream_context_create([
|
||||
'http' => [
|
||||
'method' => 'POST',
|
||||
'header' => 'Content-type: application/x-www-form-urlencoded',
|
||||
'content' => http_build_query($verifyParams),
|
||||
],
|
||||
]));
|
||||
|
||||
if ($response === false) {
|
||||
Log::error('PayPal IPN verification request failed');
|
||||
return false;
|
||||
}
|
||||
|
||||
return response('OK', 200);
|
||||
}
|
||||
|
||||
private function verifyIPN($input)
|
||||
{
|
||||
// Use PayPal SDK to verify
|
||||
// Return true/false
|
||||
return true; // Placeholder
|
||||
return trim($response) === 'VERIFIED';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,13 @@ class StripeWebhookController extends Controller
|
||||
}
|
||||
|
||||
switch ($event['type']) {
|
||||
case 'checkout.session.completed':
|
||||
$session = $event['data']['object'];
|
||||
if ($session['mode'] === 'subscription' && isset($session['metadata']['subscription']) && $session['metadata']['subscription'] === 'true') {
|
||||
$this->handleSubscriptionStarted($session);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'payment_intent.succeeded':
|
||||
$paymentIntent = $event['data']['object'];
|
||||
$this->handlePaymentIntentSucceeded($paymentIntent);
|
||||
@@ -167,4 +174,74 @@ class StripeWebhookController extends Controller
|
||||
// TODO: Deactivate package or notify tenant
|
||||
// e.g., TenantPackage::where('provider_id', $subscription)->update(['active' => false]);
|
||||
}
|
||||
|
||||
private function handleSubscriptionStarted($session)
|
||||
{
|
||||
$metadata = $session['metadata'];
|
||||
if (!$metadata['user_id'] && !$metadata['tenant_id'] || !$metadata['package_id']) {
|
||||
Log::warning('Missing metadata in Stripe checkout session: ' . $session['id']);
|
||||
return;
|
||||
}
|
||||
|
||||
$userId = $metadata['user_id'] ?? null;
|
||||
$tenantId = $metadata['tenant_id'] ?? null;
|
||||
$packageId = $metadata['package_id'];
|
||||
$type = $metadata['type'] ?? 'reseller_subscription';
|
||||
|
||||
if ($userId && !$tenantId) {
|
||||
$tenant = \App\Models\Tenant::where('user_id', $userId)->first();
|
||||
if ($tenant) {
|
||||
$tenantId = $tenant->id;
|
||||
} else {
|
||||
Log::error('Tenant not found for user_id: ' . $userId);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$tenantId) {
|
||||
Log::error('No tenant_id found for Stripe checkout session: ' . $session['id']);
|
||||
return;
|
||||
}
|
||||
|
||||
$subscriptionId = $session['subscription']['id'] ?? null;
|
||||
if (!$subscriptionId) {
|
||||
Log::error('No subscription ID in checkout session: ' . $session['id']);
|
||||
return;
|
||||
}
|
||||
|
||||
// Activate TenantPackage for initial subscription
|
||||
\App\Models\TenantPackage::updateOrCreate(
|
||||
[
|
||||
'tenant_id' => $tenantId,
|
||||
'package_id' => $packageId,
|
||||
],
|
||||
[
|
||||
'purchased_at' => now(),
|
||||
'expires_at' => now()->addYear(),
|
||||
'active' => true,
|
||||
]
|
||||
);
|
||||
|
||||
// Create initial PackagePurchase
|
||||
\App\Models\PackagePurchase::create([
|
||||
'tenant_id' => $tenantId,
|
||||
'package_id' => $packageId,
|
||||
'provider_id' => $subscriptionId,
|
||||
'price' => $session['amount_total'] / 100,
|
||||
'type' => $type,
|
||||
'purchased_at' => now(),
|
||||
'refunded' => false,
|
||||
]);
|
||||
|
||||
// Update tenant subscription fields if needed
|
||||
$tenant = \App\Models\Tenant::find($tenantId);
|
||||
if ($tenant) {
|
||||
$tenant->update([
|
||||
'subscription_id' => $subscriptionId,
|
||||
'subscription_status' => 'active',
|
||||
]);
|
||||
}
|
||||
|
||||
Log::info('Initial subscription activated via Stripe checkout session: ' . $session['id'] . ' for tenant ' . $tenantId);
|
||||
}
|
||||
}
|
||||
@@ -2,24 +2,44 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Spatie\Translatable\HasTranslations;
|
||||
use Stephenjude\FilamentBlog\Models\Category as BaseCategory;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class BlogCategory extends BaseCategory
|
||||
class BlogCategory extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes, HasTranslations;
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
protected $translatable = [
|
||||
'name',
|
||||
'description',
|
||||
];
|
||||
protected $table = 'blog_categories';
|
||||
|
||||
protected $fillable = [
|
||||
'slug',
|
||||
'is_visible',
|
||||
'translations',
|
||||
'name',
|
||||
'description',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_visible' => 'boolean',
|
||||
'name' => 'array',
|
||||
'description' => 'array',
|
||||
];
|
||||
|
||||
public function posts(): HasMany
|
||||
{
|
||||
return $this->hasMany(BlogPost::class, 'blog_category_id');
|
||||
}
|
||||
|
||||
public function scopeIsVisible(Builder $query)
|
||||
{
|
||||
return $query->where('is_visible', true);
|
||||
}
|
||||
|
||||
public function scopeIsInvisible(Builder $query)
|
||||
{
|
||||
return $query->where('is_visible', false);
|
||||
}
|
||||
}
|
||||
@@ -2,16 +2,21 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Spatie\Translatable\HasTranslations;
|
||||
use Stephenjude\FilamentBlog\Models\Post as BasePost;
|
||||
|
||||
class BlogPost extends BasePost
|
||||
class BlogPost extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes, HasTranslations;
|
||||
|
||||
protected $table = 'blog_posts';
|
||||
|
||||
protected $translatable = [
|
||||
'title',
|
||||
'excerpt',
|
||||
@@ -21,7 +26,6 @@ class BlogPost extends BasePost
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'blog_author_id',
|
||||
'blog_category_id',
|
||||
'slug',
|
||||
'banner',
|
||||
@@ -29,4 +33,33 @@ class BlogPost extends BasePost
|
||||
'is_published',
|
||||
'translations',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'published_at' => 'date',
|
||||
'is_published' => 'boolean',
|
||||
];
|
||||
|
||||
protected $appends = [
|
||||
'banner_url',
|
||||
];
|
||||
|
||||
public function bannerUrl(): Attribute
|
||||
{
|
||||
return Attribute::get(fn () => $this->banner ? asset(Storage::url($this->banner)) : '');
|
||||
}
|
||||
|
||||
public function scopePublished(Builder $query)
|
||||
{
|
||||
return $query->whereNotNull('published_at')->where('is_published', true);
|
||||
}
|
||||
|
||||
public function scopeDraft(Builder $query)
|
||||
{
|
||||
return $query->whereNull('published_at');
|
||||
}
|
||||
|
||||
public function category(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(BlogCategory::class, 'blog_category_id');
|
||||
}
|
||||
}
|
||||
@@ -5,10 +5,10 @@ namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Spatie\Tags\Tag;
|
||||
use Spatie\Translatable\HasTranslations;
|
||||
use Stephenjude\FilamentBlog\Models\Tag as BaseTag;
|
||||
|
||||
class BlogTag extends BaseTag
|
||||
class BlogTag extends Tag
|
||||
{
|
||||
use HasFactory, SoftDeletes, HasTranslations;
|
||||
|
||||
|
||||
@@ -40,7 +40,32 @@ class Package extends Model
|
||||
'features' => 'array',
|
||||
];
|
||||
|
||||
// features handled by $casts = ['features' => 'array']
|
||||
|
||||
protected function features(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: function ($value) {
|
||||
if (is_array($value)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (is_string($value)) {
|
||||
$decoded = json_decode($value, true);
|
||||
|
||||
if (is_string($decoded)) {
|
||||
$decoded = json_decode($decoded, true);
|
||||
}
|
||||
|
||||
if (json_last_error() === JSON_ERROR_NONE && is_array($decoded)) {
|
||||
return $decoded;
|
||||
}
|
||||
}
|
||||
|
||||
return [];
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function eventPackages(): HasMany
|
||||
{
|
||||
@@ -77,4 +102,4 @@ class Package extends Model
|
||||
'max_events_per_year' => $this->max_events_per_year,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,17 +26,17 @@ use App\Models\BlogCategory;
|
||||
use App\Models\BlogTag;
|
||||
use App\Filament\Widgets\PlatformStatsWidget;
|
||||
use App\Filament\Widgets\TopTenantsByUploads;
|
||||
use Stephenjude\FilamentBlog\Filament\Resources\CategoryResource;
|
||||
use Stephenjude\FilamentBlog\Filament\Resources\PostResource;
|
||||
use Stephenjude\FilamentBlog\BlogPlugin;
|
||||
use App\Filament\Blog\Resources\PostResource;
|
||||
use App\Filament\Blog\Resources\CategoryResource;
|
||||
use App\Filament\Blog\Resources\AuthorResource;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class SuperAdminPanelProvider extends PanelProvider
|
||||
{
|
||||
public function panel(Panel $panel): Panel
|
||||
{
|
||||
\Illuminate\Support\Facades\Log::info('SuperAdminPanelProvider panel method called');
|
||||
|
||||
|
||||
return $panel
|
||||
->default()
|
||||
->id('superadmin')
|
||||
@@ -50,9 +50,9 @@ class SuperAdminPanelProvider extends PanelProvider
|
||||
Pages\Dashboard::class,
|
||||
])
|
||||
->login(\App\Filament\SuperAdmin\Pages\Auth\Login::class)
|
||||
->plugin(
|
||||
/*->plugin(
|
||||
BlogPlugin::make()
|
||||
)
|
||||
)*/
|
||||
->profile()
|
||||
->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\\Filament\\Widgets')
|
||||
->widgets([
|
||||
@@ -76,8 +76,9 @@ class SuperAdminPanelProvider extends PanelProvider
|
||||
Authenticate::class,
|
||||
])
|
||||
->resources([
|
||||
// Temporär deaktiviert: TenantResource - verdächtigt für frühen Fehler
|
||||
// TenantResource::class,
|
||||
|
||||
PostResource::class,
|
||||
CategoryResource::class,
|
||||
LegalPageResource::class,
|
||||
])
|
||||
->authGuard('web')
|
||||
|
||||
Reference in New Issue
Block a user