Created
September 29, 2017 16:19
-
-
Save ryanvade/a9beedc99a05ec13461818bab4f678bb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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