#Give default value to TextInput when Edit Data

15 messages · Page 1 of 1 (latest)

stray flicker
#

This data is not in the same table so I have to get the data first in another table
Now from the data I took I want to give a default value in TextInput::make('custom_name')
How do I do that?

class OrderResource extends Resource
{

public static function form(Form $form): Form
{
    $data = $form->getRecord();
    if ($data !== null) {
       $getData = User::find($data->partner_id);
    }



    return $form
        ->schema([
        // ... form other
          Forms\Components\TextInput::make('custom_name)
                    ->label('Name')
                    ->required(),

])
}
}

The data I took I put in the $getData variable, in the $getData variable there is a name, now I want to give it to the default TextInput custom_name

amber jackalBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

ionic star
#

Should this field get update don save too? It should like you should be using a relationship

stray flicker
ionic star
#

So just group it?

Group::make([
  Forms\Components\TextInput::make('name')
    ->label('Name')
    ->required(),
])
->relationship('partnerUser')
stray flicker
ionic star
#

IT wouldn't be, because it's a relationship it'll auto-create it / update it.

stray flicker
stray flicker
stray flicker
ionic star
#

History should be stored with an observer

stray flicker
# ionic star History should be stored with an observer

Sorry, I don't understand what you mean, maybe you can explain it or maybe there are references that I can see or read?
but thank you very much for helping me, I have found a solution for that even though it may not be the best practice. but it solves my problem. thank you very much

ionic star
#

Are you familiar with Laravel in general? IF you have a solution then thats great 🙂

stray flicker
#

I just started learning laravel

ionic star
# stray flicker I just started learning laravel

Oh, so for history you would tend to build a Laravel Observer which allows you to observe the models events and as such on updated you can then store a history record or perform other actions, this is particulary useful if allow the model to be updated in multiple places.