How to Show User Fields in one to one Model in Laravel Nova? #5924
Unanswered
mohammad6006
asked this question in
Q&A
Replies: 1 comment
-
|
You could use a public function fields(NovaRequest $request): array
{
return [
ID::make()->sortable(),
Text::make('First Name', 'first_name')
->sortable()
->rules('required', 'max:255'),
Text::make('Last Name', 'last_name')
->sortable()
->rules('required', 'max:255'),
BelongsTo::make('Doctor', 'doctor', Doctor::class)
->onlyOnForms()
->showCreateRelationButton(),
HasOne::make('Doctor', 'doctor', Doctor::class)
->exceptOnForms(),
];
}Even though the relationship is not a HasOne, the HasOne field would work perfectly fine on details, for index you could implement fieldsForIndex() and use the dot notation picking you have currently |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I create a project with Laravel nova I create Doctor model and resource User and Doctor has one to one relation
User Model:
Doctor Model:
Now I want to fill user fields from Doctor resource:
Doctor resource:
In this Doctor fields:
first_name and last_name are in doctors table but user name, email and password are in users table
when I create new doctor it show
The User Name field is required.
Beta Was this translation helpful? Give feedback.
All reactions