FilamentF
Filament2y ago
Wim

Filament table: related resource with traits

I'm trying to use Laravel-Vouchers in Filament PHP. I have two models: User (implements CanRedeemVouchers) and Product (implement HasVoucher). I cannot 'see' the model Voucher as this is part of the package. So I cannot manually add a relation to between Product and Voucher (however this should be covered by the traits).

I created a form where I can add vouchers and assign them to a product. This created an entry in the voucher table:
id:1
code: AAAABBBBCCCC
model_type: App\Models\Product
model_id: 1
expires_at: 2024-1-18

In a Filament table 'Vouchers' I would like to display the product name.

I was trying as follows:

Tables\Columns\TextColumn::make('name')
    ->default(function (Product $record) {
         return $record->name;
    }),

But this clearly is not the right way. Anyone can provide little help?
Was this page helpful?