Mercurial > packages > framework
comparison src/Traits/Filterable.php @ 1:56d9c64d64aa
Setting up the base, still have plenty of work to be done here.
| author | luka |
|---|---|
| date | Mon, 09 Jun 2025 23:07:17 -0400 |
| parents | |
| children | b44434aaa767 |
comparison
equal
deleted
inserted
replaced
| 0:07e7262a8cce | 1:56d9c64d64aa |
|---|---|
| 1 <?php | |
| 2 | |
| 3 namespace Wizard\Framework\Traits; | |
| 4 | |
| 5 trait Filterable | |
| 6 { | |
| 7 protected static $filters = []; | |
| 8 | |
| 9 // End goal: 'column_name' 'operator' 'value' | |
| 10 // string: name LIKE '%test%' | |
| 11 // value: id = 3 | |
| 12 // date: | |
| 13 // | |
| 14 // | |
| 15 // table | |
| 16 // column | |
| 17 // operator ? based on the value? | |
| 18 // value | |
| 19 // required joins | |
| 20 // | |
| 21 | |
| 22 public function scopeFilter($query, $validated) | |
| 23 { | |
| 24 $filters = static::$filters; | |
| 25 | |
| 26 foreach ($filters as $key => $filter) { | |
| 27 | |
| 28 if (isset($validated[$key])) { | |
| 29 if (isset($filter['callback'])) { | |
| 30 | |
| 31 } else { | |
| 32 switch ($filter['type']) { | |
| 33 case 'value': | |
| 34 default: | |
| 35 $this->valueFilter($query, $filter, $validated[$key]); | |
| 36 } | |
| 37 } | |
| 38 } | |
| 39 } | |
| 40 } | |
| 41 | |
| 42 public function valueFilter($query, $filter, $value) | |
| 43 { | |
| 44 $query->where($filter['table'].'.'.$filter['column_name'], '=', $value); | |
| 45 } | |
| 46 | |
| 47 // filter for dates | |
| 48 public function dateFilter() {} | |
| 49 } |
