HalalSoft /
laravel-dynamic-column
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Halalsoft\LaravelDynamicColumn; |
||
| 4 | |||
| 5 | |||
| 6 | trait HasDynamicColumn |
||
| 7 | { |
||
| 8 | |||
| 9 | /** |
||
| 10 | * Boot the MariaDB Dynamic Column trait. |
||
| 11 | * |
||
| 12 | * @return void |
||
| 13 | */ |
||
| 14 | protected static function bootHasDynamicColumn() |
||
| 15 | { |
||
| 16 | static::addGlobalScope(new DynamicScope()); |
||
| 17 | static::saving( |
||
| 18 | function($model) { |
||
| 19 | foreach ($model->getCasts() as $column => $cast) { |
||
| 20 | if ($cast == 'Halalsoft\LaravelDynamicColumn\Dynamic' || $cast == "Halalsoft\LaravelDynamicColumn\DynamicObject") { |
||
| 21 | $model->$column = $model->$column; |
||
| 22 | } |
||
| 23 | } |
||
| 24 | } |
||
| 25 | ); |
||
| 26 | } |
||
| 27 | |||
| 28 | |||
| 29 | protected function newBaseQueryBuilder() |
||
| 30 | { |
||
| 31 | $connection = $this->getConnection(); |
||
| 32 | |||
| 33 | return new DynamicBuilder( |
||
| 34 | $connection, $connection->setQueryGrammar(new DynamicGrammar())->getQueryGrammar(), |
||
| 35 | $connection->getPostProcessor(), $this |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 36 | ); |
||
| 37 | } |
||
| 38 | |||
| 39 | |||
| 40 | public function getDynamicColumns() |
||
| 41 | { |
||
| 42 | $columns = []; |
||
| 43 | foreach ($this->getCasts() as $column => $cast) { |
||
| 44 | if ($cast == "Halalsoft\LaravelDynamicColumn\Dynamic" || $cast == "Halalsoft\LaravelDynamicColumn\DynamicObject") { |
||
| 45 | $columns[] = $column; |
||
| 46 | } |
||
| 47 | } |
||
| 48 | |||
| 49 | return $columns; |
||
| 50 | } |
||
| 51 | |||
| 52 | } |