TextInput, set default value (from backend)

Currently I have TextInput::make('user.name'). The name field of the user relation already have an value. However it's not showing in the forms. So how can I make it show?
Solution:
```php Group::make([ TextInput::make('name') ]) ->relationship('user')...
Jump to solution
10 Replies
toeknee
toeknee3mo ago
Scope the section to 'user' relationship and then have a single field named 'name'; Please provide the code if you need more help
atabegruslan
atabegruslanOP3mo ago
My code was like this
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('user.name')
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('user.name')
I tried your way
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('name')
->relationship('user')
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('name')
->relationship('user')
Neither way worked More help please
itsmejyv
itsmejyv3mo ago
I think, it will work in select?
Forms\Component\Select::make('name')
->relationship('User', 'name')
Forms\Component\Select::make('name')
->relationship('User', 'name')
don't forget to add
->preload()
->preload()
so it will automatically list all user upon loading of the page
atabegruslan
atabegruslanOP3mo ago
Yes, your way works for select. But how about for TextInput?
itsmejyv
itsmejyv3mo ago
it won't work in TextInput since it is text input.
atabegruslan
atabegruslanOP3mo ago
Ok. I just need a label, showing the user name in the form. How can that be done?
itsmejyv
itsmejyv3mo ago
wdym? you want to retrieve the name from user? then set it to current form?
Solution
LeandroFerreira
LeandroFerreira3mo ago
Group::make([
TextInput::make('name')
])
->relationship('user')
Group::make([
TextInput::make('name')
])
->relationship('user')
igorclauss
igorclauss3mo ago
Your code should actually do it. But you need to check if the relationships on the model is set.
atabegruslan
atabegruslanOP3mo ago
Thank you
Want results from more Discord servers?
Add your server