Textarea value from api

Hello devs, how can I make it happen I get the textarea populated with value from an api resource?
Textarea::make('public-key')
->live()
->default(function (Get $get) {
if ($get('credential_id') !== null) {
...
return $client?->getSshKeys()?->first()['public_key'];
}
})
Textarea::make('public-key')
->live()
->default(function (Get $get) {
if ($get('credential_id') !== null) {
...
return $client?->getSshKeys()?->first()['public_key'];
}
})
The textarea does not populate with the returned value.
9 Replies
JibayMcs
JibayMcs2mo ago
Hi ! Try using this:
->formatStateUsing(function(Get $get) {
if($get('credential_id')) {
//...
return $client?->getSshKeys()?->first()['public_key'];
}
})
->formatStateUsing(function(Get $get) {
if($get('credential_id')) {
//...
return $client?->getSshKeys()?->first()['public_key'];
}
})
Abdellah
AbdellahOP2mo ago
Thanks @JibayMcs . Unforturnately, it's not working
JibayMcs
JibayMcs2mo ago
Please, give me more context, it's inside a Resource ? A custom Livewire table ?
toeknee
toeknee2mo ago
Are you editing or creating? default only works on creation and only populates if you have run fill on mount.
Abdellah
AbdellahOP2mo ago
Inside a resource Creating a resource
toeknee
toeknee2mo ago
The above will work then,you need to make the credential_id live
Abdellah
AbdellahOP2mo ago
Yes. It's live. Maybe I am doing something not right
Textarea::make('public-key')
->live()
->visible(fn (Get $get) => $get('credential_id') !== null && $get('ssh-key') !== null)
->formatStateUsing(function (Get $get) {
if ($get('credential_id') !== null) {
$credential = Credential::find($get('credential_id'));
$client = new ApiClient($credential->id);
return $client?->getSshKeys()?->first()['public_key'];
}
})
Textarea::make('public-key')
->live()
->visible(fn (Get $get) => $get('credential_id') !== null && $get('ssh-key') !== null)
->formatStateUsing(function (Get $get) {
if ($get('credential_id') !== null) {
$credential = Credential::find($get('credential_id'));
$client = new ApiClient($credential->id);
return $client?->getSshKeys()?->first()['public_key'];
}
})
toeknee
toeknee2mo ago
debug it by dding each section
Abdellah
AbdellahOP2mo ago
Okay
Want results from more Discord servers?
Add your server