• <bdo id='ZgDRd'></bdo><ul id='ZgDRd'></ul>
  • <tfoot id='ZgDRd'></tfoot>
  • <legend id='ZgDRd'><style id='ZgDRd'><dir id='ZgDRd'><q id='ZgDRd'></q></dir></style></legend>

    1. <small id='ZgDRd'></small><noframes id='ZgDRd'>

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

        Laravel 在数据透视表中雄辩的 UUID

        时间:2023-09-24

      1. <legend id='gx8RI'><style id='gx8RI'><dir id='gx8RI'><q id='gx8RI'></q></dir></style></legend>

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

            <tbody id='gx8RI'></tbody>

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

                  本文介绍了Laravel 在数据透视表中雄辩的 UUID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  这个问题是这样的:laravel uuid 未显示在查询中.然而,这个问题的不同之处在于该表是一个带有 id 字段的数据透视表,使用通过 MySQL 触发器在插入时生成的 UUID.

                  This question is like this one: laravel uuid not showing in query. However, the difference in this question is about that table is a pivot table with id field uses UUID generated via MySQL trigger on insert.

                  我不想为该数据透视表创建另一个模型来为其提供类似问题的答案所考虑的解决方案.那么,有没有什么办法可以从与之相关的另一个模型中对数据透视表进行类型转换?

                  I don't want to create another model for that pivot table to supply it with the solution regarded on the similar question's answer. So, is there any way to perform type casting of the pivot table from another model related to it?

                  推荐答案

                  我想这可能是你想要的:

                  I think this might be what you want:

                  在定义 BelongsToMany 关系的模型中添加此属性:

                  In your model that defines the BelongsToMany relationship add this property:

                  protected $casts = ['relationName.pivot.id' => 'string'];
                  

                  更新

                  我想我们可以在这里使用 php7.0 中的匿名类,而不是为枢轴创建模型类:

                  I guess we can make use of anonymous classes in php7.0 here instead of creating a model class for the pivot:

                  我没有测试这段代码,所以我不知道它是否有效,这只是一个想法

                  public function activeStatuses()
                  {
                      return $this->belongsToMany('ModelName')
                                  ->using(class_basename(new class extends IlluminateDatabaseEloquentRelationsPivot {
                                      protected $casts = ['id' => 'string'];
                                  }));
                  }
                  

                  通常我更愿意为数据透视表创建模型或简单地使用数据透视类

                  Generally i would prefer to create model for the pivot table or simply use a pivot class

                  这篇关于Laravel 在数据透视表中雄辩的 UUID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Laravel - 使用 whereHas 获取最后一行 下一篇:Laravel 4:一个模型可以服务多个数据库表吗?

                  相关文章

                  最新文章

                  <legend id='WLIz0'><style id='WLIz0'><dir id='WLIz0'><q id='WLIz0'></q></dir></style></legend>

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

                        <bdo id='WLIz0'></bdo><ul id='WLIz0'></ul>

                      <tfoot id='WLIz0'></tfoot>