问题
I have a User model and via Eager Loading i am loading also the Table Profile.
To Display it i just write $user->profile->nameOfTheProfilePropertyIWant
just as normal.
Simple.
But how exactly do i use Form Model Binding now?
Normal i would use Form::text('nameOfTheUserPropertyIWant')
for a User Property like an email. But i want to set in on a Property of the Profile like the location. (profile->location)
But how can i set it to an profile property?
回答1:
You may do this (in a one-to-one
relationship) using something like this:
Form::text('profile[location]')
In this case $user->profile->location
will be populated in the given text box if an instance of User
model is bound to the from using Form::model($user)
with the related model profile
.
来源:https://stackoverflow.com/questions/23766283/laravel-eager-loading-and-form-model-binding