F
Filament10mo ago
ElCoco

Why this RepeatableEntry code doesn't work as expected

public function conversationsList(Infolist $infolist): Infolist
{
$user = User::find(auth()->id());
$conversations = $user->conversations()->select('id', 'name')->get()->toArray();
// dd($conversations);
return $infolist
->schema([
FilamentInfolists\RepeatableEntry::make('conversations')
->hiddenLabel(true)
->schema([
FilamentInfolists\TextEntry::make('id')
->hiddenLabel()
->action(Action::make('select')
->action(function (int $id) {
dd($id);
})
),
FilamentInfolists\TextEntry::make('name')
->hiddenLabel()
])
])
->state([
'conversations' => $conversations
])
->columns(1);
}
public function conversationsList(Infolist $infolist): Infolist
{
$user = User::find(auth()->id());
$conversations = $user->conversations()->select('id', 'name')->get()->toArray();
// dd($conversations);
return $infolist
->schema([
FilamentInfolists\RepeatableEntry::make('conversations')
->hiddenLabel(true)
->schema([
FilamentInfolists\TextEntry::make('id')
->hiddenLabel()
->action(Action::make('select')
->action(function (int $id) {
dd($id);
})
),
FilamentInfolists\TextEntry::make('name')
->hiddenLabel()
])
])
->state([
'conversations' => $conversations
])
->columns(1);
}
The list shows up properly, but when I click in the action I get: An attempt was made to evaluate a closure for [Filament\Infolists\Components\Actions\Action], but [$id] was unresolvable. I am trying to get the value of 'id' in the current component action. I also tried other stuff like $state or injecting Get and some desperate random stuff...Nothing seems to work. The only thing that gives sings if working is:
->action(function (array $data) {
dd($data);
})
->action(function (array $data) {
dd($data);
})
But this gives me an empty array.
2 Replies
ElCoco
ElCoco10mo ago
For anybody interested, I fix it by createing the action clousure like this:
->action(function (Action $action) {
dd($action->getInfolistComponent()->getState());
})
->action(function (Action $action) {
dd($action->getInfolistComponent()->getState());
})
Here is the full code:
public function conversationsList(Infolist $infolist): Infolist
{
// dd($conversations);
return $infolist
->schema([
FilamentInfolists\RepeatableEntry::make('conversations')
->hiddenLabel(true)
->schema([
FilamentInfolists\TextEntry::make('id')
->action(Action::make('select')
->action(function (Action $action) {
dd($action->getInfolistComponent()->getState());
})
),
FilamentInfolists\TextEntry::make('name')
->hiddenLabel()
])
])
->state($this->conversations)
->columns(1);
}
public function conversationsList(Infolist $infolist): Infolist
{
// dd($conversations);
return $infolist
->schema([
FilamentInfolists\RepeatableEntry::make('conversations')
->hiddenLabel(true)
->schema([
FilamentInfolists\TextEntry::make('id')
->action(Action::make('select')
->action(function (Action $action) {
dd($action->getInfolistComponent()->getState());
})
),
FilamentInfolists\TextEntry::make('name')
->hiddenLabel()
])
])
->state($this->conversations)
->columns(1);
}
This seems a bit gross to me, probably there is a better way...
Akshay Bokade
Akshay Bokade7mo ago
@ElCoco I am having same issue. You can do this also like, ->action(function (array $data, $record) { dd($record); But the problem is, if there are more than one records, it returns the last one only. Do you know how to overcome this issue?
Want results from more Discord servers?
Add your server
More Posts