F
Filament5mo ago
Code A

Give default value to TextInput when Edit Data

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
12 Replies
toeknee
toeknee5mo ago
Should this field get update don save too? It should like you should be using a relationship
Code A
Code AOP5mo ago
Yes, make it in the model? Like this? class Order extends Model { use HasFactory; protected $fillable = [ 'partner_id', 'address_id', 'status', ]; // other relation // partner_id from table users public function partnerUser() { return $this->belongsTo(User::class, 'partner_id'); } }
toeknee
toeknee5mo ago
So just group it?
Group::make([
Forms\Components\TextInput::make('name')
->label('Name')
->required(),
])
->relationship('partnerUser')
Group::make([
Forms\Components\TextInput::make('name')
->label('Name')
->required(),
])
->relationship('partnerUser')
Code A
Code AOP5mo ago
thanks that can help me. but when craete data how to get data that is in Group::make because when I dd($data) it is data name, and other data that is in Group::make is not in $data class OrderTask extends CreateRecord { protected static string $resource = OrderResource::class; protected function handleRecordCreation(array $data): Model { dd($data); // other data }}
toeknee
toeknee5mo ago
IT wouldn't be, because it's a relationship it'll auto-create it / update it.
Code A
Code AOP5mo ago
but I want to manipulate the data in Group::make, because the data is not just a name. and I need the data in Group::make, to create data in another table example I want to create data like this DB::table('order_status_histories')->insert($data_order_status_history); now the variable $data_order_status_history contains one of them in group:make the example above is just one example how to get the data in Group::Make? when I try to create data without manipulating the data in group:make, there is data in another table that is null or empty
toeknee
toeknee5mo ago
History should be stored with an observer
Code A
Code AOP5mo ago
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
toeknee
toeknee5mo ago
Are you familiar with Laravel in general? IF you have a solution then thats great 🙂
Code A
Code AOP5mo ago
I just started learning laravel
toeknee
toeknee5mo ago
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.
Code A
Code AOP5mo ago
Oh I understand, thank you very much for the explanation.

Did you find this page helpful?