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

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

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

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

      • <bdo id='hvhCf'></bdo><ul id='hvhCf'></ul>
      <tfoot id='hvhCf'></tfoot>

      如何自定義 Laravel 的 DatabaseQueryBuilder(制作更好的

      How to customize Laravel#39;s DatabaseQueryBuilder (make better subquery)(如何自定義 Laravel 的 DatabaseQueryBuilder(制作更好的子查詢))
      • <tfoot id='HG4Li'></tfoot>

          <tbody id='HG4Li'></tbody>

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

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

              1. <i id='HG4Li'><tr id='HG4Li'><dt id='HG4Li'><q id='HG4Li'><span id='HG4Li'><b id='HG4Li'><form id='HG4Li'><ins id='HG4Li'></ins><ul id='HG4Li'></ul><sub id='HG4Li'></sub></form><legend id='HG4Li'></legend><bdo id='HG4Li'><pre id='HG4Li'><center id='HG4Li'></center></pre></bdo></b><th id='HG4Li'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='HG4Li'><tfoot id='HG4Li'></tfoot><dl id='HG4Li'><fieldset id='HG4Li'></fieldset></dl></div>
              2. 本文介紹了如何自定義 Laravel 的 DatabaseQueryBuilder(制作更好的子查詢)的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                問(wèn)題描述

                我正在開(kāi)發(fā) Laravel 4.據(jù)我所知,我可以做子查詢:

                I'm working on Laravel 4. As I knew, I can do subquery:

                Project::whereIn('project_id', function($q) {
                    $q->select('project_id')
                        ->from('company')
                        ->whereNull('deleted_at');
                });
                

                我發(fā)現(xiàn)了一些復(fù)雜情況,即我無(wú)法在子查詢中使用作用域并禁用 soft_delete 使我對(duì)源代碼進(jìn)行了大量更改.

                I found complications, that I can't use scope in subquery and disable soft_delete make me change source code so much.

                我希望它是:

                Project::whereIn('project_id', function(&$q) {
                    $q = Company::select('project_id')->getQuery();
                });
                

                現(xiàn)在,我可以添加范圍,輕松禁用 soft_delete.

                Now, I can add scope, disable soft_delete easily.

                我嘗試并找到了一個(gè)解決方案,即我必須更改 Laravel 的 DatabaseQueryBuilder 代碼,函數(shù) whereInSub,第 786 行.

                I tried, and found a solution, that I must change Laravel's DatabaseQueryBuilder code, function whereInSub, line 786.

                call_user_func($callback, $query = $this->newQuery());
                

                到:

                $query = $this->newQuery();
                call_user_func_array($callback, array(&$query));
                

                修改 Laravel 框架的供應(yīng)商是有害的.所以想問(wèn)一下怎么安全的做.

                It's harmful to modify Laravel framework's vendor. So I want to ask how to do it safely.

                對(duì)不起,因?yàn)槲业挠⒄Z(yǔ)不好.

                Sorry because my bad English.

                感謝您的閱讀.

                推薦答案

                哦!這是一個(gè)相當(dāng)棘手的問(wèn)題,因?yàn)槟哪P蛯U(kuò)展 Eloquent,然后 Eloquent 使用 IlluminateDatabaseQueryBuilder.

                Oooh! This is quite a tricky one since your model would extend Eloquent, then Eloquent uses IlluminateDatabaseQueryBuilder.

                但我注意到 Eloquent 實(shí)際上是 app/config/app.php 文件中的別名.因此,您可以執(zhí)行以下步驟.

                But what I noticed is that Eloquent is actually an alias in app/config/app.php file. So what you can do is following these steps.

                1. 使用自定義的 whereInSub()IlluminateDatabaseQueryBuilder 擴(kuò)展到 MyQueryBuilder.
                2. IlluminateDatabaseEloquentModel 擴(kuò)展到 MyModel 并使其 use 你的 MyQueryBuilder.
                3. app/config/app.php 中的 Eloquent 別名設(shè)置為新的 MyModel 類.
                1. Extend IlluminateDatabaseQueryBuilder to MyQueryBuilder with your custom whereInSub().
                2. Extend IlluminateDatabaseEloquentModel to MyModel and make it use your MyQueryBuilder.
                3. Set Eloquent alias in app/config/app.php to your new MyModel class.

                像這樣:

                MyQueryBuilder.php:

                use Closure;
                use IlluminateSupportCollection;
                use IlluminateDatabaseConnectionInterface;
                use IlluminateDatabaseQueryGrammarsGrammar;
                use IlluminateDatabaseQueryProcessorsProcessor;
                
                class MyQueryBuilder extends IlluminateDatabaseQueryBuilder
                {
                    protected function whereInSub($column, Closure $callback, $boolean, $not)
                    {
                        $type = $not ? 'NotInSub' : 'InSub';
                
                        $query = $this->newQuery(); // Your changes
                        call_user_func_array($callback, array(&$query)); // Your changes
                
                        $this->wheres[] = compact('type', 'column', 'query', 'boolean');
                
                        $this->mergeBindings($query);
                
                        return $this;
                    }
                }
                

                MyModel.php:

                use DateTime;
                use ArrayAccess;
                use CarbonCarbon;
                use LogicException;
                use IlluminateEventsDispatcher;
                use IlluminateDatabaseEloquentRelationsPivot;
                use IlluminateDatabaseEloquentRelationsHasOne;
                use IlluminateDatabaseEloquentRelationsHasMany;
                use IlluminateDatabaseEloquentRelationsMorphTo;
                use IlluminateSupportContractsJsonableInterface;
                use IlluminateSupportContractsArrayableInterface;
                use IlluminateDatabaseEloquentRelationsRelation;
                use IlluminateDatabaseEloquentRelationsMorphOne;
                use IlluminateDatabaseEloquentRelationsMorphMany;
                use IlluminateDatabaseEloquentRelationsBelongsTo;
                // use IlluminateDatabaseQueryBuilder as QueryBuilder;
                use IlluminateDatabaseEloquentRelationsMorphToMany;
                use IlluminateDatabaseEloquentRelationsBelongsToMany;
                use IlluminateDatabaseEloquentRelationsHasManyThrough;
                use IlluminateDatabaseConnectionResolverInterface as Resolver;
                use MyQueryBuilder as QueryBuilder; // MyModel should now use your MyQueryBuilder instead of the default which I commented out above
                
                abstract class MyModel extends IlluminateDatabaseEloquentModel
                {
                
                }
                

                app/config/app.php:

                'aliases' => array(
                    ...
                    'Eloquent'        => 'MyModel',
                    ...
                );
                

                請(qǐng)注意,我將一長(zhǎng)串 use 放在那里,因?yàn)?"use" 關(guān)鍵字不會(huì)被繼承.此外,為了簡(jiǎn)單起見(jiàn),我沒(méi)有將 MyQueryBuilderMyModel 放在命名空間中.根據(jù)我們使用的 Laravel 版本,我的 use 列表也可能與您的不同,因此請(qǐng)檢查用途.

                Note that I put long lists of use up there because "use" keyword does not get inherited. Also I did not put MyQueryBuilder and MyModel in a namespace for the sake of simplicity. My use list might also be different from yours depending on Laravel versions we use, so please check the uses too.

                這篇關(guān)于如何自定義 Laravel 的 DatabaseQueryBuilder(制作更好的子查詢)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                相關(guān)文檔推薦

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

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

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

                  • <tfoot id='mtBDP'></tfoot>

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

                          主站蜘蛛池模板: 韩国精品一区 | 国产精品精品视频一区二区三区 | 99re在线播放 | 中文字幕在线一 | 正在播放一区二区 | 97精品超碰一区二区三区 | 日本成人毛片 | 久久久久se| 国产一区二区免费 | 欧美三区在线观看 | 久久精品一区二区 | 亚洲精品在线免费播放 | 国产精品久久久久久久久久久免费看 | 国产一区二区不卡 | 中文字幕精品视频 | 中文字幕亚洲精品 | 91精品国产91久久综合桃花 | 午夜性视频 | 国产综合视频 | 国产色 | 国产日韩一区二区 | 亚洲欧美网 | 青草青草久热精品视频在线观看 | 国产精品久久久久aaaa九色 | 国产精品美女久久久久aⅴ国产馆 | 久久久久久国产一区二区三区 | 99久久99热这里只有精品 | 亚洲一区二区三区在线视频 | 综合精品在线 | 香蕉久久久 | 7777在线视频 | 天天看逼 | 91 在线| 亚洲不卡一 | 亚洲电影第三页 | 福利视频一区二区三区 | 羞羞视频在线观看免费观看 | 1级毛片 | 蜜桃免费一区二区三区 | 亚洲一区在线日韩在线深爱 | 日韩不卡一区二区 |