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