Laravel Eager Loading and Form Model Binding

血红的双手。 提交于 2019-12-12 02:13:37

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!