本文整理汇总了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;
}
示例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;
});
}
示例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;
});
}
示例4: addWithDrafts
protected function addWithDrafts(Builder $builder)
{
$builder->macro('withDrafts', function (Builder $builder) {
$this->remove($builder, $builder->getModel());
return $builder;
});
}
示例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;
});
}
示例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)]);
});
}
示例7: addOnlyRegistered
protected function addOnlyRegistered(Builder $builder)
{
$builder->macro('onlyRegistered', function (Builder $builder) {
$this->remove($builder, $builder->getModel());
$builder->registered();
return $builder;
});
}
示例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;
});
}
示例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;
});
}
示例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;
});
}
示例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;
});
}
示例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;
});
}
示例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;
});
}
示例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;
});
}
示例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;
});
}