Rewrite RecipeHistory without InteractsWithTable to fix 404
Deploy / deploy (push) Successful in 17s
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:
1 parent
dd710cb1c0
commit
6f78b22285
2 files changed
+57
-37
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)
|
||||
->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();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user