1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Chuckbe\Chuckcms\Controllers; |
4
|
|
|
|
5
|
|
|
use Chuckbe\Chuckcms\Models\Page; |
6
|
|
|
use Chuckbe\Chuckcms\Models\Template; |
7
|
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests; |
8
|
|
|
use Illuminate\Foundation\Bus\DispatchesJobs; |
9
|
|
|
use Illuminate\Foundation\Validation\ValidatesRequests; |
10
|
|
|
use Illuminate\Http\Request; |
11
|
|
|
use Illuminate\Routing\Controller as BaseController; |
12
|
|
|
|
13
|
|
|
class TemplateController extends BaseController |
14
|
|
|
{ |
15
|
|
|
use AuthorizesRequests; |
16
|
|
|
use DispatchesJobs; |
17
|
|
|
use ValidatesRequests; |
18
|
|
|
|
19
|
|
|
protected $page; |
20
|
|
|
protected $template; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Create a TemplateController instance. |
24
|
|
|
* |
25
|
|
|
* @return void |
26
|
|
|
*/ |
27
|
|
|
public function __construct(Page $page, Template $template) |
28
|
|
|
{ |
29
|
|
|
$this->page = $page; |
30
|
|
|
$this->template = $template; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Show the dashboard -> templates > index. |
35
|
|
|
* |
36
|
|
|
* @return \Illuminate\View\View |
37
|
|
|
*/ |
38
|
|
|
public function index() |
39
|
|
|
{ |
40
|
|
|
$templates = $this->template->where('active', 1)->get(); |
41
|
|
|
|
42
|
|
|
$pages = $this->page->get(); |
43
|
|
|
|
44
|
|
|
return view('chuckcms::backend.templates.index', compact('templates', 'pages')); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Show the dashboard -> templates > index. |
49
|
|
|
* |
50
|
|
|
* @param string $slug |
51
|
|
|
* |
52
|
|
|
* @return \Illuminate\View\View |
53
|
|
|
*/ |
54
|
|
|
public function edit($slug) |
55
|
|
|
{ |
56
|
|
|
$template = $this->template->where('active', 1)->where('slug', $slug)->first(); |
57
|
|
|
|
58
|
|
|
return view('chuckcms::backend.templates.edit.index', compact('template')); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Show the dashboard -> templates > index. |
63
|
|
|
* |
64
|
|
|
* @param Request $request |
65
|
|
|
* |
66
|
|
|
* @return \Illuminate\Http\RedirectResponse |
67
|
|
|
*/ |
68
|
|
|
public function save(Request $request) |
69
|
|
|
{ |
70
|
|
|
$this->validate(request(), [//@todo create custom Request class for page validation |
71
|
|
|
'template_id' => 'required', |
72
|
|
|
]); |
73
|
|
|
|
74
|
|
|
$this->template->updateFromRequest($request); |
75
|
|
|
|
76
|
|
|
return redirect()->route('dashboard.templates'); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|