Rewrite RecipeHistory without InteractsWithTable to fix 404
Deploy / deploy (push) Successful in 17s

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 <noreply@anthropic.com>
This commit is contained in:
Malek TellissiandClaude Sonnet 4.6 committed 2026-09-12 18:38:37 +02:00
1 parent dd710cb1c0
commit 6f78b22285
2 files changed
+55 -35

No files matched your search

@@ -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)
return Recipe::query()
->where('product_id', $this->recordId)
->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);
->get();
}
}
@@ -1,3 +1,42 @@
<x-filament-panels::page>
{{ $this->table }}
<div class="fi-ta rounded-xl bg-white shadow-sm ring-1 ring-gray-950/5 dark:bg-gray-900 dark:ring-white/10">
<table class="w-full table-auto divide-y divide-gray-200 dark:divide-white/5 text-sm">
<thead>
<tr class="bg-gray-50 dark:bg-white/5">
<th class="px-4 py-3 text-left font-medium text-gray-600 dark:text-gray-400">Version</th>
<th class="px-4 py-3 text-left font-medium text-gray-600 dark:text-gray-400">Zutaten</th>
<th class="px-4 py-3 text-left font-medium text-gray-600 dark:text-gray-400">Erstellt am</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-100 dark:divide-white/5">
@forelse ($this->getRecipes() as $recipe)
<tr class="hover:bg-gray-50 dark:hover:bg-white/5">
<td class="px-4 py-3">
@if ($recipe->id === $this->currentRecipeId)
<span class="inline-flex items-center rounded-full bg-green-100 px-2 py-0.5 text-xs font-semibold text-green-700 dark:bg-green-500/20 dark:text-green-400">
v{{ $recipe->version }}
</span>
@else
<span class="inline-flex items-center rounded-full bg-gray-100 px-2 py-0.5 text-xs font-semibold text-gray-600 dark:bg-white/10 dark:text-gray-400">
v{{ $recipe->version }}
</span>
@endif
</td>
<td class="px-4 py-3 text-gray-700 dark:text-gray-300">
{{ $recipe->spices->map(fn ($s) => $s->name . ' ' . $s->pivot->amount_in_percent . '%')->implode(' · ') ?: '—' }}
</td>
<td class="px-4 py-3 text-gray-500 dark:text-gray-400">
{{ $recipe->created_at->format('d.m.Y H:i') }}
</td>
</tr>
@empty
<tr>
<td colspan="3" class="px-4 py-8 text-center text-gray-400">
Keine Rezeptversionen vorhanden.
</td>
</tr>
@endforelse
</tbody>
</table>
</div>
</x-filament-panels::page>