mirror of
https://github.com/robonen/education-project.git
synced 2026-03-20 02:44:31 +00:00
Создание, обновление, получение, фильтрация
This commit is contained in:
34
app/Filters/QueryFilter.php
Normal file
34
app/Filters/QueryFilter.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filters;
|
||||
|
||||
|
||||
class QueryFilter
|
||||
{
|
||||
protected $builder;
|
||||
protected $request;
|
||||
|
||||
public function __construct($builder, $request)
|
||||
{
|
||||
$this->builder = $builder;
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
public function apply()
|
||||
{
|
||||
foreach ($this->filters() as $filter => $value) {
|
||||
if (method_exists($this, $filter)) {
|
||||
if (!$value) {
|
||||
continue;
|
||||
}
|
||||
$this->$filter($value);
|
||||
}
|
||||
}
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
protected function filters()
|
||||
{
|
||||
return $this->request->all();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user