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

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

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

      <legend id='MtEkY'><style id='MtEkY'><dir id='MtEkY'><q id='MtEkY'></q></dir></style></legend>
    2. <small id='MtEkY'></small><noframes id='MtEkY'>

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

    4. Laravel,如何為關系列使用 where 條件?

      Laravel, How to use where conditions for relation#39;s column?(Laravel,如何為關系列使用 where 條件?)

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

            • <bdo id='FiBqf'></bdo><ul id='FiBqf'></ul>

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

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

                本文介紹了Laravel,如何為關系列使用 where 條件?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我正在使用 Laravel 并且在使用 Eloquent ORM 時遇到了一個小問題.我可以使用 JOIN 簡單地使用 SQL 查詢來實現它,但我似乎無法讓它與 Eloquent 一起使用!

                I'm using Laravel and having a small problem with Eloquent ORM.. I can get this working simply with SQL query using a JOIN but I can't seem to get it working with Eloquent!

                這就是我想要的,我有兩張表.一個是Restaurants",另一個是Restaurant_Facilities".

                This is what I want, I have two tabels. one is 'Restaurants' and other is 'Restaurant_Facilities'.

                表格很簡單……而且是一對一的關系.就像有一個帶有 idnameslug 等的 restaurant 表和另一個名為 restaurant_facilities 的表 帶有 idrestaurant_idwifiparking

                The tables are simple.. and One-To-One relations. like there is a restaurant table with id, name, slug, etc and another table called restaurant_facilities with id, restaurant_id, wifi, parking, etc

                現在我想做的是..加載所有wifi = 1或wifi = 0的餐廳..我怎么能用 Eloquent 做到這一點?我嘗試過急切加載、數據透視表、with()、collections(),但似乎沒有任何效果!

                Now what I want to do is.. load all restaurants which have wifi = 1 or wifi = 0.. How can i do that with Eloquent ? I have tried eager loading, pivot tables, with(), collections() and nothing seems to work!

                對于cuisines 的多對多關系,我遇到了同樣的問題!我有相同的 restaurant 表和一個 cuisine 表和一個 restaurant_cuisine_connection 表..

                The same problem I have for a Many-To-Many relation for cuisines! I have the same restaurant table and a cuisine table and a restaurant_cuisine_connection table..

                但是如何使用 ID 將所有餐廳加載到特定美食中?

                but how do I load all restaurants inside a specific cuisine using it's ID ?

                這行得通.

                Cuisine::find(6)->restaurants()->get();

                但我想從 Restaurant:: 模型加載它而不是從菜系中加載..因為我有很多條件鏈接在一起..它用于搜索和過濾/瀏覽頁面.

                but I wanna load this from Restaurant:: model not from cuisines.. because I have many conditions chained together.. its for a search and filtering / browse page.

                任何想法或方法?我已經為此苦苦掙扎了 3 天,但仍然沒有答案.

                Any ideas or ways ? I've been struggling with this for 3 days and still no answer.

                示例模型:

                class Restaurant extends Eloquent {
                
                    protected $table = 'restaurants';
                
                    public function facilities() {
                        return $this->hasOne('Facilities'); 
                    }
                }
                
                class Facilities extends Eloquent {
                
                    protected $table = 'restaurants_facilities';
                
                    public function restaurant() {
                        return $this->belongsTo('Restaurant');
                    }
                
                }
                

                附:這似乎有效..但這不是雄辯的方式嗎?

                PS : This seems to be working.. but this is not Eloquent way right ?

                Restaurant::leftJoin(
                                'cuisine_restaurant', 
                                'cuisine_restaurant.restaurant_id', 
                                '=', 'restaurants.id'
                             )
                             ->where('cuisine_id', 16)
                               ->get();
                

                還有什么是在沒有其他查詢的情況下找到具有特定列值的餐館數量的最佳方法?比如..我必須找到有停車位 = 1 和 wifi = 1 的餐廳總數?

                Also what is the best method to find a count of restaurants which have specific column value without another query ? like.. i have to find the total of restaurants which have parking = 1 and wifi = 1 ?

                請幫忙解決這個問題.

                謝謝.

                推薦答案

                如果您必須從 Restaurant 模型加載,我認為在此處執行左連接沒有任何問題.我可能會將它抽象為我的 Restaurant 模型上的一個方法,如下所示:

                I don't see anything wrong with doing the left join here, if you have to load from the Restaurant model. I might abstract it away to a method on my Restaurant model, like so:

                class Restaurant extends Eloquent {
                    protected $table = 'restaurants'; // will be default in latest L4 beta
                
                    public function facility()
                    {
                      return $this->hasOne('Facility');
                    }
                
                    // Or, better, make public, and inject instance to controller.
                    public static function withWifi()
                    {
                      return static::leftJoin(
                        'restaurant_facilities',
                        'restaurants.id', '=', 'restaurant_facilities.restaurant_id'
                      )->where('wifi', '=', 1);
                    }
                }
                

                然后,從您的路線:

                Route::get('/', function()
                {
                  return Restaurant::withWifi()->get();
                });
                

                在旅途中 - 尚未測試該代碼,但我認為它應該可以工作.您可以改為使用帶有約束的預加載,但這只會指定工具對象是否為空.除非您指定 where 子句,否則它仍會返回所有餐廳.

                On the go - haven't tested that code, but I think it should work. You could instead use eager loading with a constraint, but that will only specify whether the facility object is null or not. It would still return all restaurants, unless you specify a where clause.

                (P.S. 我會堅持使用 Facility 的單數形式.注意 hasOne('Facilities') 怎么讀不正確?)

                (P.S. I'd stick with the singular form of Facility. Notice how hasOne('Facilities') doesn't read correctly?)

                這篇關于Laravel,如何為關系列使用 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 找不到驅動程序)
              • <small id='UmGi6'></small><noframes id='UmGi6'>

                1. <tfoot id='UmGi6'></tfoot>
                2. <legend id='UmGi6'><style id='UmGi6'><dir id='UmGi6'><q id='UmGi6'></q></dir></style></legend>

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

                            <tbody id='UmGi6'></tbody>

                          主站蜘蛛池模板: 国产精品视频久久 | av成人在线观看 | 黄色av免费网站 | 国产一区二区在线播放视频 | 免费国产视频在线观看 | 欧美日韩在线观看视频网站 | 欧美精品一级 | 国产污视频在线 | 亚洲欧美一区二区三区在线 | 伊人精品在线 | 国产在线观看不卡一区二区三区 | 亚洲免费观看 | 一区在线观看视频 | 国产精品久久久久9999鸭 | 日本亚洲一区 | 久久美女网| 日韩在线不卡 | 国产ts人妖系列高潮 | 人妖无码 | 国产高清在线精品 | 热久久免费视频 | 精品久久久久一区二区国产 | 欧美日韩一区在线 | 久久成人一区二区三区 | 美女视频黄的 | 日韩欧美在线观看 | 国产精品3区 | 久草青青草 | 欧美国产精品一区二区三区 | 欧美一级片在线看 | 在线欧美亚洲 | 国产精品久久久久久久久图文区 | 婷婷国产一区二区三区 | 日韩免费 | 国产精品资源在线观看 | 日韩精品一区二区三区在线观看 | 国产丝袜一区二区三区免费视频 | 国产精品视频一区二区三区不卡 | 欧美亚洲视频在线观看 | 中国三级黄色录像 | 日韩视频在线免费观看 |