1 | <?php |
||||
2 | |||||
3 | namespace Glorand\Model\Settings\Managers; |
||||
4 | |||||
5 | use Glorand\Model\Settings\Contracts\SettingsManagerContract; |
||||
6 | use Glorand\Model\Settings\Models\ModelSettings; |
||||
7 | |||||
8 | /** |
||||
9 | * Class TableSettingsManager |
||||
10 | * @package Glorand\Model\Settings\Managers |
||||
11 | * @property \Illuminate\Database\Eloquent\Model|\Glorand\Model\Settings\Traits\HasSettingsTable $model |
||||
12 | */ |
||||
13 | class TableSettingsManager extends AbstractSettingsManager |
||||
14 | { |
||||
15 | /** |
||||
16 | * @param array $settings |
||||
17 | * @return \Glorand\Model\Settings\Contracts\SettingsManagerContract |
||||
18 | */ |
||||
19 | 6 | public function apply(array $settings = []): SettingsManagerContract |
|||
20 | { |
||||
21 | 6 | if (!$modelSettings = $this->model->modelSettings()->first()) { |
|||
22 | 6 | $modelSettings = new ModelSettings(); |
|||
23 | 6 | $modelSettings->model()->associate($this->model); |
|||
24 | } |
||||
25 | 6 | $modelSettings->settings = $settings; |
|||
26 | 6 | $modelSettings->save(); |
|||
27 | |||||
28 | 6 | return $this; |
|||
29 | } |
||||
30 | |||||
31 | /** |
||||
32 | * @param string|null $path |
||||
33 | * @return \Glorand\Model\Settings\Contracts\SettingsManagerContract |
||||
34 | * @throws \Exception |
||||
35 | */ |
||||
36 | 1 | public function delete(string $path = null): SettingsManagerContract |
|||
37 | { |
||||
38 | 1 | if (!$path) { |
|||
39 | /** @var ModelSettings $modelSettings */ |
||||
40 | 1 | if ($modelSettings = $this->model->modelSettings()->first()) { |
|||
41 | 1 | $modelSettings->delete(); |
|||
42 | } |
||||
43 | } else { |
||||
44 | 1 | $settings = $this->all(); |
|||
45 | 1 | array_forget($settings, $path); |
|||
0 ignored issues
–
show
|
|||||
46 | 1 | $this->apply($settings); |
|||
47 | } |
||||
48 | |||||
49 | 1 | return $this; |
|||
50 | } |
||||
51 | |||||
52 | /** |
||||
53 | * @param string $path |
||||
54 | * @param mixed $value |
||||
55 | * @return \Glorand\Model\Settings\Contracts\SettingsManagerContract |
||||
56 | */ |
||||
57 | 2 | public function set(string $path, $value): SettingsManagerContract |
|||
58 | { |
||||
59 | 2 | $settings = $this->all(); |
|||
60 | 2 | array_set($settings, $path, $value); |
|||
0 ignored issues
–
show
The function
array_set() has been deprecated: Arr::set() should be used directly instead. Will be removed in Laravel 5.9.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This function has been deprecated. The supplier of the function has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.
Loading history...
|
|||||
61 | |||||
62 | 2 | return $this->apply($settings); |
|||
63 | } |
||||
64 | } |
||||
65 |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.