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();
|
||||
}
|
||||
}
|
||||
40
app/Filters/TimetableFilter.php
Normal file
40
app/Filters/TimetableFilter.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filters;
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
class TimetableFilter extends QueryFilter
|
||||
{
|
||||
|
||||
protected function class($value)
|
||||
{
|
||||
$this->builder = $this->builder->where('class_id', $value);
|
||||
}
|
||||
|
||||
protected function teacher($value)
|
||||
{
|
||||
$this->builder = $this->builder->where('teacher_id', $value);
|
||||
}
|
||||
|
||||
protected function subject($value)
|
||||
{
|
||||
$this->builder = $this->builder->where('type_event', $value);
|
||||
}
|
||||
|
||||
protected function classroom($value)
|
||||
{
|
||||
$this->builder = $this->builder->where('classroom', $value);
|
||||
}
|
||||
|
||||
protected function date($value)
|
||||
{
|
||||
$start_date = str_replace('/', '-', $value);
|
||||
$end_date = Carbon::parse($start_date)
|
||||
->addDays(5)
|
||||
->format('Y-m-d');
|
||||
$this->builder = $this->builder->whereBetween('date', [$start_date, $end_date]);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user