|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Yajra\CMS\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use Yajra\CMS\DataTables\FileAssetsDataTable; |
|
6
|
|
|
use Yajra\CMS\Entities\Configuration; |
|
7
|
|
|
use App\Http\Requests; |
|
8
|
|
|
use Illuminate\Http\Request; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class SiteConfigurationController |
|
12
|
|
|
* |
|
13
|
|
|
* @package Yajra\CMS\Controllers |
|
14
|
|
|
*/ |
|
15
|
|
|
class SiteConfigurationController extends Controller |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* Site configuration setup page. |
|
19
|
|
|
* |
|
20
|
|
|
* @param \Yajra\CMS\Entities\Configuration $configuration |
|
21
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
|
22
|
|
|
*/ |
|
23
|
|
|
public function index(Configuration $configuration) |
|
24
|
|
|
{ |
|
25
|
|
|
return view('administrator.configuration.index', compact('configuration')); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Store submitted configurations. |
|
30
|
|
|
* |
|
31
|
|
|
* @param \Illuminate\Http\Request $request |
|
32
|
|
|
*/ |
|
33
|
|
|
public function store(Request $request) |
|
34
|
|
|
{ |
|
35
|
|
|
$cleanArray = $request->all(); |
|
36
|
|
|
$array = ['config' => $cleanArray['config']] + $cleanArray; // set config array value to first. |
|
37
|
|
|
|
|
38
|
|
|
$this->storeConfiguration($array); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Run submitted configurations. |
|
43
|
|
|
* |
|
44
|
|
|
* @param array $array |
|
45
|
|
|
*/ |
|
46
|
|
|
protected function storeConfiguration($array) |
|
47
|
|
|
{ |
|
48
|
|
|
foreach ($array as $key => $value) { |
|
49
|
|
|
if ($key == 'config') { |
|
50
|
|
|
$setKey = $value; |
|
51
|
|
|
} else { |
|
52
|
|
|
$cleanKey = $setKey . '.' . str_replace('AAA', '.', $key); // remove js replacement string. |
|
|
|
|
|
|
53
|
|
|
$this->removeByKey($cleanKey); |
|
54
|
|
|
Configuration::create(['key' => $cleanKey, 'value' => $value]); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Remove configuration by key. |
|
61
|
|
|
* |
|
62
|
|
|
* @param string $key |
|
63
|
|
|
* @return Configuration |
|
64
|
|
|
*/ |
|
65
|
|
|
protected function removeByKey($key) |
|
66
|
|
|
{ |
|
67
|
|
|
return Configuration::where('key', $key)->delete(); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Show all site assets. |
|
72
|
|
|
* |
|
73
|
|
|
* @param \Yajra\CMS\DataTables\FileAssetsDataTable $dataTable |
|
74
|
|
|
* @return \Illuminate\Http\JsonResponse |
|
75
|
|
|
*/ |
|
76
|
|
|
public function getAssets(FileAssetsDataTable $dataTable) |
|
77
|
|
|
{ |
|
78
|
|
|
return $dataTable->ajax(); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: