Skip to content

Instantly share code, notes, and snippets.

@ryanvade
Created September 29, 2017 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanvade/a9beedc99a05ec13461818bab4f678bb to your computer and use it in GitHub Desktop.
Save ryanvade/a9beedc99a05ec13461818bab4f678bb to your computer and use it in GitHub Desktop.
<?php
namespace Csb\Filters;
use Illuminate\Http\Request;
abstract class Filter
{
protected $request;
protected $builder;
protected $filters = [];
public function __construct(Request $request)
{
$this->request = $request;
}
public function apply($builder)
{
$this->builder = $builder;
foreach ($this->getFilters() as $filter => $value) {
if (method_exists($this, $filter)) {
$this->$filter($value);
}
}
return $this->builder;
}
private function getFilters()
{
return $this->request->intersect($this->filters);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment