pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

<tfoot id='Qzemc'></tfoot>

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

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

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

        Laravel 在 withCount 方法上使用 where 子句

        Laravel using where clause on a withCount method(Laravel 在 withCount 方法上使用 where 子句)
          <legend id='KjlbL'><style id='KjlbL'><dir id='KjlbL'><q id='KjlbL'></q></dir></style></legend>

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

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

              <tbody id='KjlbL'></tbody>

                  <bdo id='KjlbL'></bdo><ul id='KjlbL'></ul>
                • <tfoot id='KjlbL'></tfoot>
                  本文介紹了Laravel 在 withCount 方法上使用 where 子句的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在嘗試使用這段代碼對 laravel 的 eloquent 查詢構建器的 withCount 方法執行 where 子句.

                  I am trying to do a where clause on withCount method of laravel's eloquent query builder using this piece of code.

                  $posts = Post::withCount('upvotes')->where('upvotes_count', '>', 5)->get();
                  

                  這段代碼給了我這個錯誤.

                  and this code is giving me this error.

                  SQLSTATE[42S22]:未找到列:1054 未知列upvotes_count"在where 子句"(SQL:select , (select count() from upvotes whereupvotes.upvoteable_id = posts.idupvotes.upvoteable_type = AppPost) as upvotes_count from posts where upvotes_count > 5)

                  SQLSTATE[42S22]: Column not found: 1054 Unknown column 'upvotes_count' in 'where clause' (SQL: select , (select count() from upvotes where upvotes.upvoteable_id = posts.id and upvotes.upvoteable_type = AppPost) as upvotes_count from posts where upvotes_count > 5)

                  所以我可以猜測的是 upvotes_count 沒有被選中,因此沒有找到該列,但是如果我執行這段代碼.

                  So from what I can guess is that upvotes_count isn't selected and hence the column is not being found, BUT if I execute this piece of code.

                  $posts = Post::withCount('upvotes')->get();
                  

                  然后我得到這個輸出.

                  {
                  "id": 1,
                  "user_id": 15,
                  "title": "Voluptatum voluptas sint delectus unde amet quis.",
                  "created_at": "2016-10-07 13:47:48",
                  "updated_at": "2016-10-07 13:47:48",
                  "upvotes_count": 7
                  },
                  {
                  "id": 2,
                  "user_id": 2,
                  "title": "Molestiae in labore qui atque.",
                  "created_at": "2016-10-07 13:47:48",
                  "updated_at": "2016-10-07 13:47:48",
                  "upvotes_count": 2
                  },
                  

                  這基本上意味著 upvotes_count 被選中,因此我真的很困惑如何解決這個問題.

                  Which basically means that upvotes_count is being selected, hence i am really confused about how to solve this problem.

                  (下面給出了我迄今為止嘗試過的更多選項以及與之相關的相應錯誤.)

                  (More options that I tried so far are given below with the respective error associated to it.)

                  $posts = Post::where('id', $id)->withCount(['upvotes' => function($query) {
                          $query->where('upvotes_count', '>', 5);
                      }])->get();
                  

                  錯誤.

                  SQLSTATE[42S22]: Column not found: 1247 Reference 'upvotes_count' not supported (forward reference in item list) (SQL: select , (select count() from upvotes where upvotes.upvoteable_id = posts.id and upvotes.upvoteable_type = AppPost and upvotes_count > 5) as upvotes_count from posts where id =1)

                  SQLSTATE[42S22]: Column not found: 1247 Reference 'upvotes_count' not supported (forward reference in item list) (SQL: select , (select count() from upvotes where upvotes.upvoteable_id = posts.id and upvotes.upvoteable_type = AppPost and upvotes_count > 5) as upvotes_count from posts where id = 1)

                  代碼.

                  $posts = Post::where('id', $id)->with(['upvotes' => function($query) {
                          $query->select('upvoteable_id AS upvotes_count');
                      }])->where('upvotes_count', '>', 5)->get();
                  

                  $posts = AppPost::where('id', $id)->with(['upvotes' => function($query) {
                          $query->selectRaw('upvoteable_id AS upvotes_count');
                      }])->where('upvotes_count', '>', 5)->get();
                  

                  錯誤.

                  SQLSTATE[42S22]:未找到列:1054 Unknown column 'upvotes_count' in 'where clause'(SQL:從 posts 中選擇 * 其中 id = 1 和 <代碼>upvotes_count > 5)

                  SQLSTATE[42S22]: Column not found: 1054 Unknown column 'upvotes_count' in 'where clause' (SQL: select * from posts where id = 1 and upvotes_count > 5)

                  <小時>

                  我只想在與父模型有關系的 count() 方法上使用 where 子句.


                  I just want to use where clause on a count() method which is in a relationship with a parent model.

                  推薦答案

                  您可以通過使用:

                  $posts = Post::withCount('upvotes')
                           ->having('upvotes_count', '>', 5)
                           ->get();
                  

                  這篇關于Laravel 在 withCount 方法上使用 where 子句的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 找不到驅動程序)
                  <i id='fcS9Q'><tr id='fcS9Q'><dt id='fcS9Q'><q id='fcS9Q'><span id='fcS9Q'><b id='fcS9Q'><form id='fcS9Q'><ins id='fcS9Q'></ins><ul id='fcS9Q'></ul><sub id='fcS9Q'></sub></form><legend id='fcS9Q'></legend><bdo id='fcS9Q'><pre id='fcS9Q'><center id='fcS9Q'></center></pre></bdo></b><th id='fcS9Q'></th></span></q></dt></tr></i><div class="q2wyecs" id='fcS9Q'><tfoot id='fcS9Q'></tfoot><dl id='fcS9Q'><fieldset id='fcS9Q'></fieldset></dl></div>

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

                            <tbody id='fcS9Q'></tbody>
                          <tfoot id='fcS9Q'></tfoot>
                        • <small id='fcS9Q'></small><noframes id='fcS9Q'>

                            主站蜘蛛池模板: 恒温槽_恒温水槽_恒温水浴槽-上海方瑞仪器有限公司 | 湖南自考_湖南自学考试 | 【铜排折弯机,钢丝折弯成型机,汽车发泡钢丝折弯机,线材折弯机厂家,线材成型机,铁线折弯机】贝朗折弯机厂家_东莞市贝朗自动化设备有限公司 | 桌上式超净工作台-水平送风超净工作台-上海康路仪器设备有限公司 | 石英陶瓷,石英坩埚,二氧化硅陶瓷-淄博百特高新材料有限公司 | HDPE储罐_厂家-山东九州阿丽贝防腐设备 | 江苏南京多语种翻译-专业翻译公司报价-正规商务翻译机构-南京华彦翻译服务有限公司 | 环氧树脂地坪_防静电地坪漆_环氧地坪漆涂料厂家-地壹涂料地坪漆 环球电气之家-中国专业电气电子产品行业服务网站! | 120kv/2mA直流高压发生器-60kv/2mA-30kva/50kv工频耐压试验装置-旭明电工 | 厚壁钢管-厚壁无缝钢管-小口径厚壁钢管-大口径厚壁钢管 - 聊城宽达钢管有限公司 | 油冷式_微型_TDY电动滚筒_外装_外置式电动滚筒厂家-淄博秉泓机械有限公司 | 苹果售后维修点查询,苹果iPhone授权售后维修服务中心 – 修果网 拼装地板,悬浮地板厂家,悬浮式拼装运动地板-石家庄博超地板科技有限公司 | 东莞工厂厂房装修_无尘车间施工_钢结构工程安装-广东集景建筑装饰设计工程有限公司 | TYPE-C厂家|TYPE-C接口|TYPE-C防水母座|TYPE-C贴片-深圳步步精 | 机制砂选粉机_砂石选粉机厂家-盐城市助成粉磨科技有限公司 | 回收二手冲床_金丰旧冲床回收_协易冲床回收 - 大鑫机械设备 | 上海办公室装修,写字楼装修—启鸣装饰设计工程有限公司 | 沈阳真空机_沈阳真空包装机_沈阳大米真空包装机-沈阳海鹞真空包装机械有限公司 | 时代北利离心机,实验室离心机,医用离心机,低速离心机DT5-2,美国SKC采样泵-上海京工实业有限公司 工业电炉,台车式电炉_厂家-淄博申华工业电炉有限公司 | 河南空气能热水器-洛阳空气能采暖-洛阳太阳能热水工程-洛阳润达高科空气能商行 | lcd条形屏-液晶长条屏-户外广告屏-条形智能显示屏-深圳市条形智能电子有限公司 | 电动卫生级调节阀,电动防爆球阀,电动软密封蝶阀,气动高压球阀,气动对夹蝶阀,气动V型调节球阀-上海川沪阀门有限公司 | Pos机办理_个人商户免费POS机申请-拉卡拉办理网| CTAB,表面活性剂1631溴型(十六烷基三甲基溴化铵)-上海升纬化工原料有限公司 | 阳光模拟试验箱_高低温试验箱_高低温冲击试验箱_快速温变试验箱|东莞市赛思检测设备有限公司 | 安徽合肥项目申报咨询公司_安徽合肥高新企业项目申报_安徽省科技项目申报代理 | 免费分销系统 — 分销商城系统_分销小程序开发 -【微商来】 | 衬塑设备,衬四氟设备,衬氟设备-淄博鲲鹏防腐设备有限公司 | 飞歌臭氧发生器厂家_水处理臭氧发生器_十大臭氧消毒机品牌 | 东亚液氮罐-液氮生物容器-乐山市东亚机电工贸有限公司 | 小型UV打印机-UV平板打印机-大型uv打印机-UV打印机源头厂家 |松普集团 | 5L旋转蒸发器-20L-50L旋转蒸发器-上海越众仪器设备有限公司 | 单级/双级旋片式真空泵厂家,2xz旋片真空泵-浙江台州求精真空泵有限公司 | 百方网-百方电气网,电工电气行业专业的B2B电子商务平台 | 无锡网站建设_小程序制作_网站设计公司_无锡网络公司_网站制作 | 油罐车_加油机_加油卷盘_加油机卷盘_罐车人孔盖_各类球阀_海底阀等车用配件厂家-湖北华特专用设备有限公司 | 广东西屋电气有限公司-广东西屋电气有限公司 | 二维运动混料机,加热型混料机,干粉混料机-南京腾阳干燥设备厂 | 双相钢_双相不锈钢_双相钢圆钢棒_双相不锈钢报价「海新双相钢」 双能x射线骨密度检测仪_dxa骨密度仪_双能x线骨密度仪_品牌厂家【品源医疗】 | RS系列电阻器,RK_RJ启动调整电阻器,RQ_RZ电阻器-上海永上电器有限公司 | 动环监控_机房环境监控_DCIM_机房漏水检测-斯特纽 |