<tfoot id='dHHmK'></tfoot>

    • <bdo id='dHHmK'></bdo><ul id='dHHmK'></ul>
    1. <small id='dHHmK'></small><noframes id='dHHmK'>

      1. <legend id='dHHmK'><style id='dHHmK'><dir id='dHHmK'><q id='dHHmK'></q></dir></style></legend>
        <i id='dHHmK'><tr id='dHHmK'><dt id='dHHmK'><q id='dHHmK'><span id='dHHmK'><b id='dHHmK'><form id='dHHmK'><ins id='dHHmK'></ins><ul id='dHHmK'></ul><sub id='dHHmK'></sub></form><legend id='dHHmK'></legend><bdo id='dHHmK'><pre id='dHHmK'><center id='dHHmK'></center></pre></bdo></b><th id='dHHmK'></th></span></q></dt></tr></i><div id='dHHmK'><tfoot id='dHHmK'></tfoot><dl id='dHHmK'><fieldset id='dHHmK'></fieldset></dl></div>

        laravel ownsTo 给出 null

        时间:2023-09-22

        <small id='jnLDD'></small><noframes id='jnLDD'>

        <tfoot id='jnLDD'></tfoot>

        <i id='jnLDD'><tr id='jnLDD'><dt id='jnLDD'><q id='jnLDD'><span id='jnLDD'><b id='jnLDD'><form id='jnLDD'><ins id='jnLDD'></ins><ul id='jnLDD'></ul><sub id='jnLDD'></sub></form><legend id='jnLDD'></legend><bdo id='jnLDD'><pre id='jnLDD'><center id='jnLDD'></center></pre></bdo></b><th id='jnLDD'></th></span></q></dt></tr></i><div id='jnLDD'><tfoot id='jnLDD'></tfoot><dl id='jnLDD'><fieldset id='jnLDD'></fieldset></dl></div>
      2. <legend id='jnLDD'><style id='jnLDD'><dir id='jnLDD'><q id='jnLDD'></q></dir></style></legend>
          <tbody id='jnLDD'></tbody>

                  <bdo id='jnLDD'></bdo><ul id='jnLDD'></ul>
                  本文介绍了laravel ownsTo 给出 null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  laravel 中的 belongsTo 关系返回 null

                  belongsTo relation in laravel is returning null

                  public function games(){
                      return $this->belongsTo('AppModelsGame');
                    }
                  

                  但是当我提供密钥作为参数时,它似乎工作正常

                  but when i provide key as argument it seems to work fine

                    public function games(){
                          return $this->belongsTo('AppModelsGame','game_id');
                        }
                  

                  但根据 docs game_id 本身就是一个默认参数.我在这里缺少什么小东西.

                  but as per the docs game_id is itself is a default argument. What is the small thing i am missing here.

                  谢谢

                  推荐答案

                  关系的 belongsTo 端根据关系方法的名称构建外键名称.这种行为不同于关系的 hasOne/hasMany 端,后者使用类的名称.

                  The belongsTo side of the relationship builds the foreign key name based on the name of the relationship method. This behavior is different than the hasOne/hasMany side of the relationship, which uses the name of the class.

                  在本例中,您的关系方法名为 games,因此它将查找外键字段 games_id.您可以提供外键字段作为第二个参数,如您所示,或者您可以将您的关系方法重命名为 game().

                  In this case, your relationship method is named games, so it will look for the foreign key field games_id. You can either provide the foreign key field as the second parameter, as you have shown, or you can rename your relationship method to game().

                  这篇关于laravel ownsTo 给出 null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:数据仅在 Laravel 应用程序中插入最后一个数组 下一篇:Laravel Eloquent ORM 返回 stdClass 而不是实际模型

                  相关文章

                  最新文章

                  <i id='9rEjJ'><tr id='9rEjJ'><dt id='9rEjJ'><q id='9rEjJ'><span id='9rEjJ'><b id='9rEjJ'><form id='9rEjJ'><ins id='9rEjJ'></ins><ul id='9rEjJ'></ul><sub id='9rEjJ'></sub></form><legend id='9rEjJ'></legend><bdo id='9rEjJ'><pre id='9rEjJ'><center id='9rEjJ'></center></pre></bdo></b><th id='9rEjJ'></th></span></q></dt></tr></i><div id='9rEjJ'><tfoot id='9rEjJ'></tfoot><dl id='9rEjJ'><fieldset id='9rEjJ'></fieldset></dl></div>

                  <small id='9rEjJ'></small><noframes id='9rEjJ'>

                    <legend id='9rEjJ'><style id='9rEjJ'><dir id='9rEjJ'><q id='9rEjJ'></q></dir></style></legend>

                      <bdo id='9rEjJ'></bdo><ul id='9rEjJ'></ul>

                    1. <tfoot id='9rEjJ'></tfoot>