久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

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

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

    2. <legend id='MxI3D'><style id='MxI3D'><dir id='MxI3D'><q id='MxI3D'></q></dir></style></legend>

      1. <tfoot id='MxI3D'></tfoot>
      2. Laravel 如何在 Eloquent 模型中添加自定義函數?

        Laravel how to add a custom function in an Eloquent model?(Laravel 如何在 Eloquent 模型中添加自定義函數?)
          <bdo id='rur6u'></bdo><ul id='rur6u'></ul>

          1. <tfoot id='rur6u'></tfoot>

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

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

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

                • 本文介紹了Laravel 如何在 Eloquent 模型中添加自定義函數?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我有一個產品模型

                  class Product extends Model
                  {
                      ...
                  
                      public function prices()
                      {
                          return $this->hasMany('AppPrice');
                      }
                  
                      ...
                  }
                  

                  我想添加一個返回最低價格的函數,在控制器中我可以使用以下方法獲取值:

                  I want to add a function which will return the lowest price, and in controller I can get the value using:

                  Product::find(1)->lowest;
                  

                  我在產品模型中添加了這個:

                  I added this in Product model:

                  public function lowest()
                  {
                      return $this->prices->min('price');
                  }
                  

                  但我收到一條錯誤消息:

                  but I got an error saying:

                  Relationship method must return an object of type IlluminateDatabaseEloquentRelationsRelation
                  

                  如果我使用 Product::find(1)->lowest();,它會起作用.是否可以讓 Product::find(1)->lowest; 工作?

                  And if I use Product::find(1)->lowest();, it will work. Is it possible to get Product::find(1)->lowest; to work?

                  任何幫助將不勝感激.

                  推薦答案

                  當您嘗試將模型中的函數作為變量訪問時,laravel 假定您正在嘗試檢索相關模型.他們稱它們為動態屬性.您需要的是自定義屬性.

                  When you try to access a function in the model as a variable, laravel assumes you're trying to retrieve a related model. They call them dynamic properties. What you need instead is a custom attribute.

                  Laravel 6 文檔:https://laravel.com/docs/6.x/雄辯的變異者

                  Laravel 6 docs: https://laravel.com/docs/6.x/eloquent-mutators

                  將以下方法添加到您的模型中:

                  add following method to your model:

                  public function getLowestAttribute()
                  {
                      //do whatever you want to do
                      return 'lowest price';
                  }
                  

                  現在您應該可以像這樣訪問它:

                  Now you should be able to access it like this:

                  Product::find(1)->lowest;
                  

                  這篇關于Laravel 如何在 Eloquent 模型中添加自定義函數?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                  PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標不起作用)
                  PHP PDO ODBC connection(PHP PDO ODBC 連接)
                  Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術方法)
                  php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                  MSSQL PDO could not find driver(MSSQL PDO 找不到驅動程序)
                    <tbody id='JcEZZ'></tbody>

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

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

                          • <tfoot id='JcEZZ'></tfoot>
                            主站蜘蛛池模板: 国产99热精品 | 亚洲欧美激情精品一区二区 | 毛片一区二区三区 | 日韩av免费看 | 91久久久精品国产一区二区蜜臀 | 天天操天天干天天爽 | 国产第二页 | 可以在线观看av的网站 | 欧美一a| 午夜视频在线观看网站 | 91精品国产乱码麻豆白嫩 | 国产一区二区在线看 | 日本不卡一区 | av黄色在线观看 | 97在线播放| 国产91久久久久久久免费 | 中文字幕在线观看一区 | 欧美激情区 | 久久久久国产精品午夜一区 | www.夜夜骑 | 懂色av色香蕉一区二区蜜桃 | 好姑娘高清在线观看电影 | 午夜播放器在线观看 | 91高清视频在线观看 | www.婷婷亚洲基地 | 久久久久久久夜 | 日日干干夜夜 | 五月天国产 | 国产精品亚洲一区二区三区在线 | 亚洲情综合五月天 | 日韩一区二区三区在线 | 成人一区二区三区在线 | 国产精品久久久久久久久久久久久 | 成人免费在线视频 | 日日操夜夜摸 | 成人一区二区三区在线观看 | 午夜成人免费视频 | 精品在线 | 国产精品久久久久久影院8一贰佰 | 男人阁久久 | 激情国产在线 |