|
1
|
|
|
<?php |
|
2
|
|
|
namespace Xetaravel\Models\Repositories; |
|
3
|
|
|
|
|
4
|
|
|
use Illuminate\Support\Str; |
|
5
|
|
|
use Xetaravel\Models\Setting; |
|
6
|
|
|
|
|
7
|
|
|
class SettingRepository |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* Create a new setting instance. |
|
11
|
|
|
* |
|
12
|
|
|
* @param array $data The data used to create the setting. |
|
13
|
|
|
* |
|
14
|
|
|
* @return \Xetaravel\Models\Setting |
|
15
|
|
|
*/ |
|
16
|
|
|
public static function create(array $data): Setting |
|
17
|
|
|
{ |
|
18
|
|
|
return Setting::create([ |
|
19
|
|
|
'name' => Str::slug($data['name'], '.'), |
|
20
|
|
|
'value_int' => $data['type'] == 'value_int' ? (int) $data['value'] : null, |
|
21
|
|
|
'value_str' => $data['type'] == 'value_str' ? (string) $data['value'] : null, |
|
22
|
|
|
'value_bool' => $data['type'] == 'value_bool' ? (bool) $data['value'] : null, |
|
23
|
|
|
'description' => $data['description'], |
|
24
|
|
|
'is_deletable' => isset($data['is_deletable']) ? true : false, |
|
25
|
|
|
]); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Update the Setting informations after a valid update request. |
|
30
|
|
|
* |
|
31
|
|
|
* @param array $data The data used to update the setting. |
|
32
|
|
|
* @param \Xetaravel\Models\Setting $setting The setting to update. |
|
33
|
|
|
* |
|
34
|
|
|
* @return bool |
|
35
|
|
|
*/ |
|
36
|
|
|
public static function update(array $data, Setting $setting): bool |
|
37
|
|
|
{ |
|
38
|
|
|
$setting->name = Str::slug($data['name'], '.'); |
|
|
|
|
|
|
39
|
|
|
$setting->value_int = $data['type'] == 'value_int' ? (int) $data['value'] : null; |
|
|
|
|
|
|
40
|
|
|
$setting->value_str = $data['type'] == 'value_str' ? (string) $data['value'] : null; |
|
|
|
|
|
|
41
|
|
|
$setting->value_bool = $data['type'] == 'value_bool' ? (bool) $data['value'] : null; |
|
|
|
|
|
|
42
|
|
|
$setting->description = $data['description']; |
|
|
|
|
|
|
43
|
|
|
$setting->is_deletable = isset($data['is_deletable']) ? true : false; |
|
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
return $setting->save(); |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|