From 6f78b22285b65c997d60507d1feca02809bdd5d3 Mon Sep 17 00:00:00 2001 From: Malek Tellissi Date: Sat, 12 Sep 2026 18:38:37 +0200 Subject: [PATCH] Rewrite RecipeHistory without InteractsWithTable to fix 404 The Filament table boot lifecycle (bootedInteractsWithTable) fires before mount(), causing issues with typed $record properties on custom resource pages. Replaced with a plain Page + Blade view rendering recipes directly. Co-Authored-By: Claude Sonnet 4.6 --- .../ProductResource/Pages/RecipeHistory.php | 53 ++++++------------- .../pages/recipe-history.blade.php | 41 +++++++++++++- 2 files changed, 57 insertions(+), 37 deletions(-) diff --git a/app/Filament/User/Resources/ProductResource/Pages/RecipeHistory.php b/app/Filament/User/Resources/ProductResource/Pages/RecipeHistory.php index 00ab36c..a7487ba 100644 --- a/app/Filament/User/Resources/ProductResource/Pages/RecipeHistory.php +++ b/app/Filament/User/Resources/ProductResource/Pages/RecipeHistory.php @@ -7,29 +7,28 @@ use App\Models\Product; use App\Models\Recipe; use Filament\Actions\Action; use Filament\Resources\Pages\Page; -use Filament\Tables\Columns\IconColumn; -use Filament\Tables\Columns\TextColumn; -use Filament\Tables\Concerns\InteractsWithTable; -use Filament\Tables\Contracts\HasTable; -use Filament\Tables\Table; -class RecipeHistory extends Page implements HasTable +class RecipeHistory extends Page { - use InteractsWithTable; - protected static string $resource = ProductResource::class; protected static string $view = 'filament.user.resources.product-resource.pages.recipe-history'; - public Product $record; + public int $recordId; + public string $productTitle = ''; + public int $currentRecipeId = 0; public function mount(int|string $record): void { - $this->record = Product::with('recipe')->findOrFail($record); + $product = Product::findOrFail($record); + + $this->recordId = $product->id; + $this->productTitle = $product->title; + $this->currentRecipeId = (int) $product->recipes_id; } public function getTitle(): string { - return 'Rezept-Versionen · ' . $this->record->title; + return 'Rezept-Versionen · ' . $this->productTitle; } protected function getHeaderActions(): array @@ -39,34 +38,16 @@ class RecipeHistory extends Page implements HasTable ->label('Zurück zum Produkt') ->icon('heroicon-o-arrow-left') ->color('gray') - ->url(ProductResource::getUrl('edit', ['record' => $this->record])), + ->url(fn () => ProductResource::getUrl('edit', ['record' => $this->recordId])), ]; } - public function table(Table $table): Table + public function getRecipes(): \Illuminate\Support\Collection { - return $table - ->query(fn () => Recipe::query() - ->where('product_id', $this->record->id) - ->with('spices') - ->orderByDesc('version') - ) - ->columns([ - TextColumn::make('version') - ->label('Version') - ->formatStateUsing(fn ($state) => 'v' . $state) - ->badge() - ->color(fn (Recipe $recipe) => $recipe->id === $this->record->recipes_id ? 'success' : 'gray'), - TextColumn::make('spices_summary') - ->label('Zutaten') - ->state(fn (Recipe $recipe) => - $recipe->spices->map(fn ($s) => $s->name . ' ' . $s->pivot->amount_in_percent . '%')->implode(' · ') - ), - TextColumn::make('created_at') - ->label('Erstellt am') - ->dateTime('d.m.Y H:i') - ->sortable(), - ]) - ->paginated(false); + return Recipe::query() + ->where('product_id', $this->recordId) + ->with('spices') + ->orderByDesc('version') + ->get(); } } diff --git a/resources/views/filament/user/resources/product-resource/pages/recipe-history.blade.php b/resources/views/filament/user/resources/product-resource/pages/recipe-history.blade.php index ce096a2..b8721df 100644 --- a/resources/views/filament/user/resources/product-resource/pages/recipe-history.blade.php +++ b/resources/views/filament/user/resources/product-resource/pages/recipe-history.blade.php @@ -1,3 +1,42 @@ - {{ $this->table }} +
+ + + + + + + + + + @forelse ($this->getRecipes() as $recipe) + + + + + + @empty + + + + @endforelse + +
VersionZutatenErstellt am
+ @if ($recipe->id === $this->currentRecipeId) + + v{{ $recipe->version }} + + @else + + v{{ $recipe->version }} + + @endif + + {{ $recipe->spices->map(fn ($s) => $s->name . ' ' . $s->pivot->amount_in_percent . '%')->implode(' · ') ?: '—' }} + + {{ $recipe->created_at->format('d.m.Y H:i') }} +
+ Keine Rezeptversionen vorhanden. +
+