我有一个用户模型,并通过Eager加载,我也在加载表配置文件.
I have a User model and via Eager Loading i am loading also the Table Profile.
要显示它,我只需像平常一样写$user->profile->nameOfTheProfilePropertyIWant.
To Display it i just write $user->profile->nameOfTheProfilePropertyIWant just as normal.
简单.
但是我现在到底该如何使用表单模型绑定? 正常情况下,我会将Form::text('nameOfTheUserPropertyIWant')用于诸如电子邮件之类的用户属性.但是我想在配置文件的属性上设置类似的位置. (配置文件->位置)
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?
推荐答案您可以使用以下方式(以one-to-one关系)进行此操作:
You may do this (in a one-to-one relationship) using something like this:
Form::text('profile[location]')在这种情况下,如果将User模型的实例绑定到与相关模型profile一起使用的Form::model($user),则将在给定的文本框中填充$user->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.
更多推荐
Laravel渴望加载和表单模型绑定
发布评论