<bdo id='fUAUM'></bdo><ul id='fUAUM'></ul>
  • <legend id='fUAUM'><style id='fUAUM'><dir id='fUAUM'><q id='fUAUM'></q></dir></style></legend>
  • <small id='fUAUM'></small><noframes id='fUAUM'>

    <tfoot id='fUAUM'></tfoot>

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

      2. Laravel 渴望加载多态关系

        Laravel Eager Loading Polymorphic Relationships(Laravel 渴望加载多态关系)
      3. <small id='gMWOa'></small><noframes id='gMWOa'>

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

            <tbody id='gMWOa'></tbody>
            <bdo id='gMWOa'></bdo><ul id='gMWOa'></ul>

                  <legend id='gMWOa'><style id='gMWOa'><dir id='gMWOa'><q id='gMWOa'></q></dir></style></legend><tfoot id='gMWOa'></tfoot>

                1. 本文介绍了Laravel 渴望加载多态关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  尝试预先加载模型及其相关模型,但相关模型返回 null,即使它具有相关数据.

                  Trying to eager load a model and it's related model but the related model returns null even though it has related data.

                  组模型对 Game 或 Gamer 具有 1:1 的多态性.

                  组模型关系:

                  public function groupable()
                  {
                      return $this->morphTo();
                  }
                  

                  游戏模型关系:

                  public function group()
                  {
                      return $this->morphOne('Group', 'groupable');
                  }
                  

                  玩家模型关系:

                  public function group()
                  {
                      return $this->morphOne('Group', 'groupable');
                  }
                  

                  查询加载组然后游戏:

                  $group = Group::whereSubdomain($id)->first();
                  $game = $group->game;
                  

                  组返回组,但游戏返回 null.

                  这是 Groups 表的示例数据库条目:

                  id    subdomain    groupable_id    groupable_type
                  5     Starmade     10              Game
                  

                  这是 Games 表的示例数据库条目:

                  id    genre    rating
                  10    7        4.5
                  

                  不知道我哪里错了没有游戏返回.

                  Not sure where I am going wrong to have no game returned.

                  推荐答案

                  试试这个.这可能会有所帮助.

                  Try this. It might help.

                      public function groupable()
                  {
                      return $this->morphTo('groupable');
                  }
                  

                  我之前也遇到过这个问题,也许你和我有同样的问题.基本上我所做的是帮助 Laravel 找到它需要查找的列.

                  I had that problem too earlier, maybe you have the same prob like me. Essentially what I did was to help Laravel finds what columns it needs to look up for.

                  这篇关于Laravel 渴望加载多态关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Laravel 4 - Connect to other database(Laravel 4 - 连接到其他数据库)
                  Call external API function from controller, LARAVEL 4(从控制器调用外部 API 函数,LARAVEL 4)
                  Empty string instead of null values Eloquent(空字符串而不是空值 Eloquent)
                  quot;laravel.logquot; could not be opened: failed to open stream(“laravel.log无法打开:无法打开流)
                  Displaying the Error Messages in Laravel after being Redirected from controller(从控制器重定向后在 Laravel 中显示错误消息)
                  Laravel Creating Dynamic Routes to controllers from Mysql database(Laravel 从 Mysql 数据库创建到控制器的动态路由)
                2. <tfoot id='BIQlt'></tfoot>

                      • <bdo id='BIQlt'></bdo><ul id='BIQlt'></ul>

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

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

                            <tbody id='BIQlt'></tbody>
                          <legend id='BIQlt'><style id='BIQlt'><dir id='BIQlt'><q id='BIQlt'></q></dir></style></legend>