【问题标题】:Laravel Eager Loading and Form Model BindingLaravel 热切加载和表单模型绑定
【发布时间】:2014-07-09 02:20:51
【问题描述】:

我有一个用户模型,通过 Eager Loading 我也在加载表配置文件。

要显示它,我只需像往常一样写$user->profile->nameOfTheProfilePropertyIWant

简单。

但是我现在究竟如何使用表单模型绑定? 正常情况下,我会将Form::text('nameOfTheUserPropertyIWant') 用于电子邮件等用户属性。但我想设置个人资料的属性,比如位置。 (个人资料->位置)

但是如何将其设置为配置文件属性?

【问题讨论】:

    标签: laravel laravel-4


    【解决方案1】:

    您可以使用以下方式(在one-to-one 关系中)执行此操作:

    Form::text('profile[location]')
    

    在这种情况下,如果User 模型的实例绑定到使用Form::model($user) 和相关模型profile 的源,则$user->profile->location 将填充到给定文本框中。

    【讨论】:

    • 你是最棒的!谢谢!
    • 如果多一层?类似: $user->profile->location->x ?
    猜你喜欢
    • 2013-05-28
    • 2020-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-02
    • 1970-01-01
    • 2013-07-13
    • 2014-12-02
    相关资源
    最近更新 更多