1 | <?php |
||
2 | |||
3 | namespace Glorand\Model\Settings\Traits; |
||
4 | |||
5 | use Glorand\Model\Settings\Contracts\SettingsManagerContract; |
||
6 | use Glorand\Model\Settings\Managers\TableSettingsManager; |
||
7 | use Glorand\Model\Settings\Models\ModelSettings; |
||
8 | use Illuminate\Database\Eloquent\Relations\MorphOne; |
||
9 | |||
10 | /** |
||
11 | * Trait HasSettingsTable |
||
12 | * @package Glorand\Model\Settings\Traits |
||
13 | * @property ModelSettings $modelSettings |
||
14 | * @property array $settings |
||
15 | * @method morphOne($model, $name) |
||
16 | */ |
||
17 | trait HasSettingsTable |
||
18 | { |
||
19 | /** |
||
20 | * @param string|null $path |
||
21 | * @param null $default |
||
1 ignored issue
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||
22 | * @return \Glorand\Model\Settings\Contracts\SettingsManagerContract |
||
23 | */ |
||
24 | public function settings(string $path = null, $default = null): SettingsManagerContract |
||
25 | { |
||
26 | return $path ? $this->settings()->get($path, $default) : new TableSettingsManager($this); |
||
27 | } |
||
28 | |||
29 | protected function getSettingsAttribute() |
||
30 | { |
||
31 | if ($this->modelSettings) { |
||
32 | return $this->modelSettings->settings; |
||
33 | } else { |
||
34 | return []; |
||
35 | } |
||
36 | } |
||
37 | |||
38 | protected function modelSettings(): MorphOne |
||
39 | { |
||
40 | return $this->morphOne(ModelSettings::class, 'model'); |
||
41 | } |
||
42 | } |
||
43 |