Laravel渴望加载和表单模型绑定

编程入门 行业动态 更新时间:2024-10-27 12:36:53
本文介绍了Laravel渴望加载和表单模型绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个用户模型,并通过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渴望加载和表单模型绑定

本文发布于:2023-08-04 06:05:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1293632.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表单   绑定   模型   加载   Laravel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!