Skip to content

Instantly share code, notes, and snippets.

@renalpha
Last active April 9, 2019 09:02
Show Gist options
  • Select an option

  • Save renalpha/1505c6c278b17a04fde6344fdfa16fe4 to your computer and use it in GitHub Desktop.

Select an option

Save renalpha/1505c6c278b17a04fde6344fdfa16fe4 to your computer and use it in GitHub Desktop.
Dedicated builder object
<?php
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
class Team extends Model
{
public function newEloquentBuilder(Builder $builder)
{
return new TeamBuilder($builder);
}
public function scopeWherePrivate(Builder $builder)
{
$builder->where('is_public', '=', false);
return $this;
}
}
<?php
use Illuminate\Database\Eloquent\Builder;
class TeamBuilder extends Builder
{
public function whereActive()
{
$this->where('is_active', '=', true);
return $this;
}
}
@renalpha

renalpha commented Apr 2, 2019

Copy link
Copy Markdown
Author

Usage:

Team::query()->whereActive()->wherePrivate();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment