当前位置: 首页>>代码示例>>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;未经允许,请勿转载。