當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Builder::macro方法代碼示例

本文整理匯總了PHP中Illuminate\Database\Eloquent\Builder::macro方法的典型用法代碼示例。如果您正苦於以下問題:PHP Builder::macro方法的具體用法?PHP Builder::macro怎麽用?PHP Builder::macro使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Illuminate\Database\Eloquent\Builder的用法示例。


在下文中一共展示了Builder::macro方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: newEloquentBuilder

 public function newEloquentBuilder($query)
 {
     $builder = new Builder($query);
     $builder->macro('key', function (Builder $builder) {
         return $builder->getQuery()->key();
     });
     $builder->macro('flush', function (Builder $builder) {
         return $builder->getQuery()->flush();
     });
     return $builder;
 }
開發者ID:angejia,項目名稱:pea,代碼行數:11,代碼來源:Model.php

示例2: addWithTrashed

 /**
  * 使用方法withTrashedUseTo來移除apply添加的條件
  * @param \Illuminate\Database\Eloquent\Builder $builder
  * @return void
  */
 protected function addWithTrashed(Builder $builder)
 {
     $builder->macro('withTrashedUseTo', function (Builder $builder) {
         $this->remove($builder, $builder->getModel());
         return $builder;
     });
 }
開發者ID:windqyoung,項目名稱:utils,代碼行數:12,代碼來源:UseToScope.php

示例3: addAllTypes

 /**
  * Extend Builder with custom method.
  *
  * @param \Illuminate\Database\Eloquent\Builder  $builder
  */
 protected function addAllTypes(Builder $builder)
 {
     $builder->macro('allTypes', function (Builder $builder) {
         $this->remove($builder);
         return $builder;
     });
 }
開發者ID:hrmshandy,項目名稱:core-cms,代碼行數:12,代碼來源:PostTypeScope.php

示例4: addWithDrafts

 protected function addWithDrafts(Builder $builder)
 {
     $builder->macro('withDrafts', function (Builder $builder) {
         $this->remove($builder, $builder->getModel());
         return $builder;
     });
 }
開發者ID:k1ng440,項目名稱:laravel-global-scope,代碼行數:7,代碼來源:PublishedScope.php

示例5: addUnordered

 /**
  * Extend Builder with custom method
  *
  * @param \Illuminate\Database\Eloquent\Builder $builder
  */
 protected function addUnordered(Builder $builder)
 {
     $builder->macro('unordered', function (Builder $builder) {
         $this->remove($builder, $builder->getModel());
         return $builder;
     });
 }
開發者ID:czim,項目名稱:laravel-pxlcms,代碼行數:12,代碼來源:PositionOrderedScope.php

示例6: apply

 /**
  * Apply the scope to a given Eloquent query builder.
  *
  * @param  \Illuminate\Database\Eloquent\Builder  $builder
  * @return void
  */
 public function apply(Builder $builder)
 {
     $model = $builder->getModel();
     $builder->whereNotNull($model->getQualifiedActivatedAtColumn());
     $builder->macro('withDeactivated', function (Builder $builder) {
         $this->remove($builder);
         return $builder;
     });
     $builder->macro('onlyDeactivated', function (Builder $builder) {
         $model = $builder->getModel();
         $this->remove($builder);
         $builder->getQuery()->whereNotNull($model->getQualifiedActivatedAtColumn());
         return $builder;
     });
     $builder->macro('deactivate', function (Builder $builder) {
         $model = $builder->getModel();
         $builder->withDeactivated();
         return $builder->update([$model->getActivatedAtColumn() => null]);
     });
     $builder->macro('activate', function (Builder $builder) {
         $model = $this->getModel();
         $query = $model->newQuery()->where($model->getKeyName(), $model->getKey());
         $model->{$model->getActivatedAtColumn()} = $time = $model->freshTimestamp();
         $query->update([$model->getActivatedAtColumn() => $model->fromDateTime($time)]);
     });
 }
開發者ID:niclasleonbock,項目名稱:eloquent-activatable,代碼行數:32,代碼來源:ActivatableScope.php

示例7: addOnlyRegistered

 protected function addOnlyRegistered(Builder $builder)
 {
     $builder->macro('onlyRegistered', function (Builder $builder) {
         $this->remove($builder, $builder->getModel());
         $builder->registered();
         return $builder;
     });
 }
開發者ID:ruly1992,項目名稱:elearning,代碼行數:8,代碼來源:PublicableScope.php

示例8: addOnlyOffline

 /**
  * Add the only-trashed extension to the builder.
  *
  * @param  \Illuminate\Database\Eloquent\Builder $builder
  * @return void
  */
 protected function addOnlyOffline(Builder $builder)
 {
     $builder->macro('onlyOffline', function (Builder $builder) {
         $model = $builder->getModel();
         $builder->withoutGlobalScope($this)->where($model->getQualifiedStatusColumn(), '=', false);
         return $builder;
     });
 }
開發者ID:SchizoDuckie,項目名稱:Expendable,代碼行數:14,代碼來源:StatusScope.php

示例9: addOnlyRegistered

 protected function addOnlyRegistered(Builder $builder)
 {
     $builder->macro('onlyRegistered', function (Builder $builder) {
         $this->remove($builder, $builder->getModel());
         $builder->where('type', 'private')->where('status', 'publish');
         return $builder;
     });
 }
開發者ID:singgihsap,項目名稱:elearning,代碼行數:8,代碼來源:PublishedScope.php

示例10: addOnlyDrafts

 /**
  * Add the onlyDrafts extension to the builder.
  *
  * @param \Illuminate\Database\Eloquent\Builder $builder
  */
 protected function addOnlyDrafts(Builder $builder)
 {
     $builder->macro('onlyDrafts', function (Builder $builder) {
         $this->remove($builder);
         $builder->getQuery()->where($this->getDraftColumn($builder), '1');
         return $builder;
     });
 }
開發者ID:anahkiasen,項目名稱:arrounded,代碼行數:13,代碼來源:DraftScope.php

示例11: addOnlyOldVersions

 /**
  * @param Builder $builder
  */
 protected function addOnlyOldVersions(Builder $builder)
 {
     $builder->macro('onlyOldVersions', function (Builder $builder) {
         $model = $builder->getModel();
         $builder->withoutGlobalScope($this)->where($model->getQualifiedIsCurrentVersionColumn(), 0);
         return $builder;
     });
 }
開發者ID:sbarre,項目名稱:eloquent-versioned,代碼行數:11,代碼來源:VersioningScope.php

示例12: addOnlyOldVersions

 /**
  * @param Builder $builder
  */
 protected function addOnlyOldVersions(Builder $builder)
 {
     $builder->macro('onlyOldVersions', function (Builder $builder) {
         $model = $builder->getModel();
         $this->remove($builder, $model);
         $builder->getQuery()->where($model->getQualifiedIsCurrentVersionColumn(), 0);
         return $builder;
     });
 }
開發者ID:arcstone,項目名稱:eloquent-versioned,代碼行數:12,代碼來源:VersioningScope.php

示例13: addOnlyArchived

 protected function addOnlyArchived(Builder $builder)
 {
     $builder->macro('onlyArchived', function (Builder $builder) {
         $model = $builder->getModel();
         $this->remove($builder, $model);
         $builder->getQuery()->whereNotNull($model->getQualifiedArchivedAtColumn());
         return $builder;
     });
 }
開發者ID:laratools,項目名稱:laratools,代碼行數:9,代碼來源:ArchivableScope.php

示例14: extend

 /**
  * Extend the Eloquent query builder.
  *
  * @param  \Illuminate\Database\Eloquent\Builder  $builder
  * @return void
  */
 protected function extend(BuilderBase $builder)
 {
     $builder->macro('orderBy', function ($builder, $column, $direction = 'asc') {
         if ($this->scopeApplied) {
             $this->remove($builder, $builder->getModel());
         }
         $builder->getQuery()->orderBy($column, $direction);
         return $builder;
     });
 }
開發者ID:jBOKA,項目名稱:library,代碼行數:16,代碼來源:SortableScope.php

示例15: addWithDrafts

 protected function addWithDrafts(Builder $builder)
 {
     $builder->macro('withDrafts', function (Builder $builder) {
         $this->remove($builder, $builder->getModel());
         $builder->with(['article' => function ($query) {
             $query->withDrafts();
         }]);
         return $builder;
     });
 }
開發者ID:ruly1992,項目名稱:elearning,代碼行數:10,代碼來源:HasArticleScope.php


注:本文中的Illuminate\Database\Eloquent\Builder::macro方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。