1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Yajra\CMS\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
6
|
|
|
use Yajra\CMS\Entities\Configuration; |
7
|
|
|
use Yajra\CMS\Theme\Repository; |
8
|
|
|
|
9
|
|
|
class ThemesController extends Controller |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var \Yajra\CMS\Theme\Repository |
13
|
|
|
*/ |
14
|
|
|
protected $themes; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* ThemesController constructor. |
18
|
|
|
* |
19
|
|
|
* @param \Yajra\CMS\Theme\Repository $themes |
20
|
|
|
*/ |
21
|
|
|
public function __construct(Repository $themes) |
22
|
|
|
{ |
23
|
|
|
$this->themes = $themes; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Display themes resource. |
28
|
|
|
* |
29
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
30
|
|
|
*/ |
31
|
|
|
public function index() |
32
|
|
|
{ |
33
|
|
|
$themes = $this->themes->all(); |
34
|
|
|
|
35
|
|
|
return view('administrator.themes.index', compact('themes')); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Store new default theme. |
40
|
|
|
* |
41
|
|
|
* @param \Illuminate\Http\Request $request |
42
|
|
|
* @return \Illuminate\Http\RedirectResponse |
43
|
|
|
*/ |
44
|
|
|
public function store(Request $request) |
45
|
|
|
{ |
46
|
|
|
/** @var Configuration $config */ |
47
|
|
|
$config = Configuration::query()->firstOrCreate(['key' => 'theme.frontend']); |
48
|
|
|
$config->value = $request->get('theme'); |
49
|
|
|
$config->save(); |
50
|
|
|
|
51
|
|
|
flash()->success(trans('cms::theme.success', ['theme' => $request->get('theme')])); |
|
|
|
|
52
|
|
|
|
53
|
|
|
return back(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Uninstall a theme. |
58
|
|
|
* |
59
|
|
|
* @param string $theme |
60
|
|
|
* @return \Illuminate\Http\RedirectResponse |
61
|
|
|
*/ |
62
|
|
|
public function destroy($theme) |
63
|
|
|
{ |
64
|
|
|
if ($this->themes->uninstall($theme)) { |
65
|
|
|
flash()->success(trans('cms::theme.deleted', compact('theme'))); |
|
|
|
|
66
|
|
|
} else { |
67
|
|
|
flash()->error(trans('cms::theme.error', compact('theme'))); |
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return back(); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.