|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Thinkone\NovaPageSettings\Model; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Builder; |
|
6
|
|
|
use Illuminate\Database\Eloquent\Factories\Factory; |
|
7
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory; |
|
8
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
9
|
|
|
use Thinkone\NovaPageSettings\Factories\PageSettingFactory; |
|
10
|
|
|
|
|
11
|
|
|
class PageSetting extends Model |
|
12
|
|
|
{ |
|
13
|
|
|
use HasFactory; |
|
14
|
|
|
|
|
15
|
|
|
protected $guarded = []; |
|
16
|
|
|
|
|
17
|
4 |
|
public function getTable(): string |
|
18
|
|
|
{ |
|
19
|
4 |
|
return config('nova-page-settings.default.settings_table'); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
1 |
|
protected static function newFactory(): Factory |
|
23
|
|
|
{ |
|
24
|
1 |
|
return PageSettingFactory::new(); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
3 |
|
public function newCollection(array $models = []): PageSettingsCollection |
|
28
|
|
|
{ |
|
29
|
3 |
|
return new PageSettingsCollection($models); |
|
|
|
|
|
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
3 |
|
public function scopePage(Builder $query, string $slug) |
|
33
|
|
|
{ |
|
34
|
3 |
|
return $query->where('page', '=', $slug); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
2 |
|
public function scopeKey(Builder $query, string $key) |
|
38
|
|
|
{ |
|
39
|
2 |
|
return $query->where('key', '=', $key); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
1 |
|
public function valueArray(): array |
|
43
|
|
|
{ |
|
44
|
1 |
|
if(is_array($this->value)) { |
|
|
|
|
|
|
45
|
1 |
|
return $this->value; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
1 |
|
$data = json_decode($this->value, true); |
|
49
|
|
|
|
|
50
|
1 |
|
return is_array($data) ? $data : []; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
1 |
|
public function valueBool(): bool |
|
54
|
|
|
{ |
|
55
|
1 |
|
return (bool) ($this->value); |
|
|
|
|
|
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
1 |
|
public function valueString(): string |
|
59
|
|
|
{ |
|
60
|
|
|
try { |
|
61
|
1 |
|
return (string) ($this->value); |
|
|
|
|
|
|
62
|
1 |
|
} catch (\Exception $e) { |
|
|
|
|
|
|
63
|
1 |
|
return ''; |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|