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
toeknee5mo 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
atabegruslanOP4mo 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
itsmejyv4mo 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
atabegruslanOP4mo ago
Yes, your way works for select. But how about for TextInput?
itsmejyv
itsmejyv4mo ago
it won't work in TextInput since it is text input.
atabegruslan
atabegruslanOP4mo ago
Ok. I just need a label, showing the user name in the form. How can that be done?
itsmejyv
itsmejyv4mo ago
wdym? you want to retrieve the name from user? then set it to current form?
Solution
LeandroFerreira
LeandroFerreira4mo ago
Group::make([
TextInput::make('name')
])
->relationship('user')
Group::make([
TextInput::make('name')
])
->relationship('user')
igorclauss
igorclauss4mo ago
Your code should actually do it. But you need to check if the relationships on the model is set.
atabegruslan
atabegruslanOP4mo ago
Thank you
Want results from more Discord servers?
Add your server