Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ahmeda's avatar

How to put value into the input in filamentphp

I have in UserResource file this static method

    public static function getBlockedUserFrom(User $record): array
    {
        return [
            Forms\Components\Toggle::make('is_blocked')
                ->label(__('Order Blocked')),

            Forms\Components\Textarea::make('blocked_message')
                ->label(__('Blocked Message'))
        ];
    }

And in the EditUser file I have this method:

protected function getActions(): array
    {
        return array_merge(parent::getActions(), [
            ButtonAction::make('block')
                ->label(__('Block User'))
                ->color('danger')
                ->action(function (array $data) {
                    $this->record->update([
                        'is_blocked' => $data['is_blocked'],
                        'blocked_message' => $data['blocked_message'],
                    ]);
                })
                ->form(UserResource::getBlockedUserFrom($this->record))
                ->requiresConfirmation(),
        ]);
    }

Basically, this creates a modal in the edit user page ...

I need to put a value in blocked_message that the user already did, cuz now when I add a message and then open the modal again the blocked_message input is empty even if the message exists in DB,

0 likes
6 replies
tisuchi's avatar

@ahmeda I think can use the value method to set the initial value of the input in the Textarea component like this:

Forms\Components\Textarea::make('blocked_message')
    ->label(__('Blocked Message'))
    ->value($this->record->blocked_message),

You can do the same for the toggle component.

Forms\Components\Toggle::make('is_blocked')
                ->label(__('Order Blocked'))
                ->value($this->record->is_blocked)

Re: https://filamentphp.com/docs/2.x/forms/fields#textarea

ahmeda's avatar

@tisuchi it is not working

Method Filament\Forms\Components\Toggle::value does not exist

1 like
tykus's avatar

@ahmeda what is the context; do you have access to the Filament\Resources\Form instance?

ebeneoyen's avatar

Forms\Components\Toggle::make('is_blocked') ->label(__('Order Blocked')) ->default($this->record->is_blocked)

Please or to participate in this conversation.