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

    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="qwawimqqmiuu" 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="qwawimqqmiuu" 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="qwawimqqmiuu" 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. 主站蜘蛛池模板: 久久精品国产一区二区电影 | 午夜在线免费观看 | 国产精品精品视频一区二区三区 | 高清国产午夜精品久久久久久 | 日韩成人一区二区 | 午夜看电影在线观看 | 四虎最新视频 | 久久久久久91 | 国外成人在线视频 | 午夜视频在线免费观看 | 国产美女自拍视频 | 日韩在线一区二区 | 国产亚洲精品美女久久久久久久久久 | 免费高清av | 欧美黄色精品 | 天天摸天天干 | 欧美黄色片 | 欧美福利影院 | 欧美精品乱码99久久影院 | 欧美一级片在线播放 | 四虎免费视频 | 一级黄色片网站 | 成人精品鲁一区一区二区 | 美女操网站 | 激情一区二区三区 | 中文字幕成人免费视频 | 欧美精品一区二区三区在线 | 久久久精品视频免费看 | 国产精品国产精品国产专区不蜜 | 国产精品永久免费视频 | 午夜影院中文字幕 | 久久亚洲综合 | 欧美视频xxx | 久久一区二区视频 | 岛国av免费观看 | 久久69精品久久久久久国产越南 | 国产精品久久久久久久粉嫩 | 欧美一区二区三区日韩 | 99精品国自产在线观看 | 午夜电影日韩 | 日本免费视频 |