Call another model inside repeater, it is possible?

I want to use another model inside repeater form like this
->maxValue(fn(Inventory $record) => dd($record))
->maxValue(fn(Inventory $record) => dd($record))
but get error like this
App\Filament\Resources\InventoryLocationResource::App\Filament\Resources\{closure}(): Argument #1 ($record) must be of type App\Models\Inventory, App\Models\InventoryLocationList given, called in D:\asc\vendor\filament\support\src\Concerns\EvaluatesClosures.php on line 35
App\Filament\Resources\InventoryLocationResource::App\Filament\Resources\{closure}(): Argument #1 ($record) must be of type App\Models\Inventory, App\Models\InventoryLocationList given, called in D:\asc\vendor\filament\support\src\Concerns\EvaluatesClosures.php on line 35
Solution:
Ahh in a text column is different. So remove the Inventory from your $record. But what is InventoryLocationList, is it a model? can you access inventory from that model? if so: $record->inventory->qty ?
Jump to solution
6 Replies
toeknee
toeknee2mo ago
You can't do that since the record is passed in. What are you trying to do?
thyk123
thyk1232mo ago
Thank you for your respond! I really appriciate it! I want to count how many item that left to reserved, user can choose how many their want to use as long as the reserved quantity, but i want to count the reserved by relationship count like code below, because only stored in db stock quantity
Tables\Columns\TextColumn::make('inventory_location_list')
->label('Reserved')
->formatStateUsing(fn(Inventory $record) => $record->qty-$record->inventory_location_list->count()),
Tables\Columns\TextColumn::make('inventory_location_list')
->label('Reserved')
->formatStateUsing(fn(Inventory $record) => $record->qty-$record->inventory_location_list->count()),
Solution
toeknee
toeknee2mo ago
Ahh in a text column is different. So remove the Inventory from your $record. But what is InventoryLocationList, is it a model? can you access inventory from that model? if so: $record->inventory->qty ?
thyk123
thyk1232mo ago
Yes it's a model, and yes it's has relationship to inventory
class InventoryLocationList extends Model
{
public function inventory(): BelongsTo
{
return $this->BelongsTo(Inventory::class);
}
}
class InventoryLocationList extends Model
{
public function inventory(): BelongsTo
{
return $this->BelongsTo(Inventory::class);
}
}
toeknee
toeknee2mo ago
So the above will work then
thyk123
thyk1232mo ago
Thank you, it works! It seem like i need to take break so i can rest my brain because even simple solution i cant find XD