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

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

    2. <small id='HciZB'></small><noframes id='HciZB'>

      <legend id='HciZB'><style id='HciZB'><dir id='HciZB'><q id='HciZB'></q></dir></style></legend>
    3. <i id='HciZB'><tr id='HciZB'><dt id='HciZB'><q id='HciZB'><span id='HciZB'><b id='HciZB'><form id='HciZB'><ins id='HciZB'></ins><ul id='HciZB'></ul><sub id='HciZB'></sub></form><legend id='HciZB'></legend><bdo id='HciZB'><pre id='HciZB'><center id='HciZB'></center></pre></bdo></b><th id='HciZB'></th></span></q></dt></tr></i><div class="5jffxjb" id='HciZB'><tfoot id='HciZB'></tfoot><dl id='HciZB'><fieldset id='HciZB'></fieldset></dl></div>
        <bdo id='HciZB'></bdo><ul id='HciZB'></ul>

        如何在使用 eloquent 時排除某些列

        How to exclude certains columns while using eloquent(如何在使用 eloquent 時排除某些列)
          <tbody id='DTG6n'></tbody>
        • <tfoot id='DTG6n'></tfoot>

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

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

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

                • <i id='DTG6n'><tr id='DTG6n'><dt id='DTG6n'><q id='DTG6n'><span id='DTG6n'><b id='DTG6n'><form id='DTG6n'><ins id='DTG6n'></ins><ul id='DTG6n'></ul><sub id='DTG6n'></sub></form><legend id='DTG6n'></legend><bdo id='DTG6n'><pre id='DTG6n'><center id='DTG6n'></center></pre></bdo></b><th id='DTG6n'></th></span></q></dt></tr></i><div class="tjfdlj5" id='DTG6n'><tfoot id='DTG6n'></tfoot><dl id='DTG6n'><fieldset id='DTG6n'></fieldset></dl></div>
                • 本文介紹了如何在使用 eloquent 時排除某些列的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  當我使用 eloquent 時,我可以使用where"方法,然后使用get"方法來填充包含我在數據庫中選擇的對象的對象.我的意思是:

                  When I'm using eloquent, I can use the "where" method then the method 'get' to fill an object containing what I've selected in my database. I mean:

                  $users = User::where('gender', 'M')->where('is_active', 1)->get(['pseudo', 'email', 'age', 'created_at'])->toArray();
                  

                  在這里我可以選擇我想要的列,如偽"、電子郵件"等.但是我在 laravel doc 中想念的是相反的方法.可能是這樣的:

                  Here I can choose the columns I want to get like 'pseudo', 'email', etc.. But what I miss in laravel doc is the way to do the contrary. It could be something like that:

                  $users = User::where('gender', 'M')->where('is_active', 1)->notGet(['pseudo', 'email', 'age', 'created_at'])->toArray();
                  

                  感謝您的回答,祝您有美好的一天.

                  Thank you for you futur answer and have a nice day.

                  推薦答案

                  如果您只需要從模型的數組或 JSON 表示中隱藏屬性,您可以使用一種或兩種方法:

                  If you only need to hide attributes from your model's array or JSON representation, you may use one or both approaches:

                  • 添加$hidden 屬性給你的模型
                  • Add the $hidden property to your model
                  class User extends Model
                  {
                      /**
                       * The attributes that should be hidden for arrays.
                       */
                       protected $hidden = ['password'];
                  }
                  

                • 使用makeHidden功能

                  $users = $users->makeHidden(['address', 'phone_number']);
                  

                • 有關更多詳細信息,請參閱其他答案... 但是 有時您不想將大量數據(地理空間、html、日志...)加載到您的應用程序中,它會很慢并且需要更多的記憶.OP 要求進行 SQL 查詢,因此我的回答是,但大多數情況下,僅從 JSON 響應中隱藏數據會更方便.

                  See other answers for more details... But sometimes you don't want to load huge data (geospatial, html, logs...) into your application, it will be slow and take more memory. OP asked for an SQL query hence my answer, but most of the time it's more convenient to only hide the data from the JSON response.

                  AFAIK SQL 中沒有內置選項來顯式排除列,所以 Laravel 不能這樣做.但是你可以試試這個技巧

                  AFAIK there is no build in option in SQL to exclude columns explicitly, so Laravel can't do it. But you can try this trick

                  更新

                  另一個技巧是指定模型中的所有列(或使用額外的查詢來使用 $this->getTableColumns() 從 這個答案,也可以在每次遷移后緩存以避免兩次查詢)然后添加一個局部作用域 函數

                  Another trick is to specify all columns in your model (or use an extra query to get all columns using $this->getTableColumns() from this answer, it can also be cached after each migration to avoid two queries) then add a local scope function

                  // The below code requires you to define all columns in $columns.
                  // A better approach is to query the schema of the table and cache it after each  
                  // migration, for more details: https://stackoverflow.com/a/56425794/3192276
                  
                  protected $columns = ['id','pseudo','email'];
                  
                  public function scopeExclude($query, $value = []) 
                  {
                      return $query->select(array_diff($this->columns, (array) $value));
                  }
                  

                  然后你可以這樣做:

                  $users = User::where('gender', 'M')
                      ->where('is_active', 1)
                      ->exclude(['pseudo', 'email', 'age', 'created_at'])
                      ->toArray();
                  

                  這篇關于如何在使用 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='HcllA'></tbody>
                  • <bdo id='HcllA'></bdo><ul id='HcllA'></ul>

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

                  • <small id='HcllA'></small><noframes id='HcllA'>

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

                          1. 主站蜘蛛池模板: 济南电缆桥架|山东桥架-济南航丰实业有限公司 | 无缝钢管-聊城无缝钢管-小口径无缝钢管-大口径无缝钢管 - 聊城宽达钢管有限公司 | 山东石英砂过滤器,除氟过滤器「价格低」-淄博胜达水处理 | 湖南印刷厂|长沙印刷公司|画册印刷|挂历印刷|台历印刷|杂志印刷-乐成印刷 | 办公室家具公司_办公家具品牌厂家_森拉堡办公家具【官网】 | 华禹护栏|锌钢护栏_阳台护栏_护栏厂家-华禹专注阳台护栏、楼梯栏杆、百叶窗、空调架、基坑护栏、道路护栏等锌钢护栏产品的生产销售。 | 民用音响-拉杆音响-家用音响-ktv专用音响-万昌科技 | 钢骨架轻型板_膨石轻型板_钢骨架轻型板价格_恒道新材料 | 智成电子深圳tdk一级代理-提供TDK电容电感贴片蜂鸣器磁芯lambda电源代理经销,TDK代理商有哪些TDK一级代理商排名查询。-深圳tdk一级代理 | 石牌坊价格石牌坊雕刻制作_石雕牌坊牌楼石栏杆厂家_山东嘉祥石雕有限公司 | 药品/药物稳定性试验考察箱-埃里森仪器设备(上海)有限公司 | 杭州公司变更法人-代理记账收费价格-公司注销代办_杭州福道财务管理咨询有限公司 | 杜甫仪器官网|实验室平行反应器|升降水浴锅|台式低温循环泵 | 深圳希玛林顺潮眼科医院(官网)│深圳眼科医院│医保定点│香港希玛林顺潮眼科中心连锁品牌 | 智慧钢琴-电钢琴-便携钢琴-数码钢琴-深圳市特伦斯乐器有限公司 | jrs高清nba(无插件)直播-jrs直播低调看直播-jrs直播nba-jrs直播 上海地磅秤|电子地上衡|防爆地磅_上海地磅秤厂家–越衡称重 | 国资灵活用工平台_全国灵活用工平台前十名-灵活用工结算小帮手 | 国际船舶网 - 船厂、船舶、造船、船舶设备、航运及海洋工程等相关行业综合信息平台 | 四探针电阻率测试仪-振实密度仪-粉末流动性测定仪-宁波瑞柯微智能 | 公交驾校-北京公交驾校欢迎您! 工作心得_读书心得_学习心得_找心得体会范文就上学道文库 | YAGEO国巨电容|贴片电阻|电容价格|三星代理商-深圳市巨优电子有限公司 | 高清视频编码器,4K音视频编解码器,直播编码器,流媒体服务器,深圳海威视讯技术有限公司 | 全自动面膜机_面膜折叠机价格_面膜灌装机定制_高速折棉机厂家-深圳市益豪科技有限公司 | 环境模拟实验室_液体-气体控温机_气体控温箱_无锡双润冷却科技有限公司 | 便携式谷丙转氨酶检测仪|华图生物科技百科| 楼承板-开闭口楼承板-无锡海逵楼承板| 胶水,胶粘剂,AB胶,环氧胶,UV胶水,高温胶,快干胶,密封胶,结构胶,电子胶,厌氧胶,高温胶水,电子胶水-东莞聚力-聚厉胶粘 | 山东锐智科电检测仪器有限公司_超声波测厚仪,涂层测厚仪,里氏硬度计,电火花检漏仪,地下管线探测仪 | 冷库安装厂家_杭州冷库_保鲜库建设-浙江克冷制冷设备有限公司 | 干法制粒机_智能干法制粒机_张家港市开创机械制造有限公司 | 土壤检测仪器_行星式球磨仪_土壤团粒分析仪厂家_山东莱恩德智能科技有限公司 | EPK超声波测厚仪,德国EPK测厚仪维修-上海树信仪器仪表有限公司 | 色谱柱-淋洗液罐-巴罗克试剂槽-巴氏吸管-5ml样品瓶-SBS液氮冻存管-上海希言科学仪器有限公司 | 皮带机-带式输送机价格-固定式胶带机生产厂家-河南坤威机械 | 高硼硅玻璃|水位计玻璃板|光学三棱镜-邯郸奥维玻璃科技有限公司 高温高压釜(氢化反应釜)百科 | 深圳活动策划公司|庆典策划|专业公关活动策划|深圳艺典文化传媒 重庆中专|职高|技校招生-重庆中专招生网 | 微量水分测定仪_厂家_卡尔费休微量水分测定仪-淄博库仑 | 广西绿桂涂料--承接隔热涂料、隔音涂料、真石漆、多彩仿石漆等涂料工程双包施工 | 深圳市源和塑胶电子有限公司-首页| 电镀电源整流器_高频电解电源_单脉双脉冲电源 - 东阳市旭东电子科技 | 硫酸钡厂家_高光沉淀硫酸钡价格-河南钡丰化工有限公司 |