1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Larafolio\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use Larafolio\Models\Page; |
6
|
|
|
use Illuminate\Http\Request; |
7
|
|
|
use Larafolio\Http\Content\ContentCrud; |
8
|
|
|
use Larafolio\Http\Requests\AddResourceRequest; |
9
|
|
|
|
10
|
|
|
class PageController extends Controller |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Service class for content crud. |
14
|
|
|
* |
15
|
|
|
* @var Larafolio\Http\Content\ContentCrud |
16
|
|
|
*/ |
17
|
|
|
protected $contentCrud; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Construct. |
21
|
|
|
* |
22
|
|
|
* @param Larafolio\Http\Content\ContentCrud $contentCrud Service class for crud. |
23
|
|
|
*/ |
24
|
|
|
public function __construct(ContentCrud $contentCrud) |
25
|
|
|
{ |
26
|
|
|
parent::__construct(); |
27
|
|
|
|
28
|
|
|
$this->contentCrud = $contentCrud; |
|
|
|
|
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Return all projects. |
33
|
|
|
* |
34
|
|
|
* @return \Illuminate\Http\JsonResponse |
35
|
|
|
*/ |
36
|
|
|
public function index() |
37
|
|
|
{ |
38
|
|
|
return $this->contentCrud->index(Page::all()); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Show an individual page in the manager. |
43
|
|
|
* |
44
|
|
|
* @param string $slug Slug of the page to show. |
45
|
|
|
* |
46
|
|
|
* @return \Illuminate\Http\Response |
47
|
|
|
*/ |
48
|
|
|
public function show($slug) |
49
|
|
|
{ |
50
|
|
|
$page = Page::withBlocks($slug)->firstOrFail(); |
|
|
|
|
51
|
|
|
|
52
|
|
|
return $this->contentCrud->show($page, 'page'); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Return the page create page. |
57
|
|
|
* |
58
|
|
|
* @return \Illuminate\Http\Response |
59
|
|
|
*/ |
60
|
|
|
public function create() |
61
|
|
|
{ |
62
|
|
|
return $this->contentCrud->create('page'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Add a new page to the portfolio. |
67
|
|
|
* |
68
|
|
|
* @param Larafolio\Http\Requests\AddResourceRequest $request Form request. |
69
|
|
|
* |
70
|
|
|
* @return \Illuminate\Http\Response |
71
|
|
|
*/ |
72
|
|
|
public function store(AddResourceRequest $request) |
73
|
|
|
{ |
74
|
|
|
return $this->contentCrud->store($request, $this->user, 'page'); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Return the page edit form view. |
79
|
|
|
* |
80
|
|
|
* @param string $slug Slug for the page to edit. |
81
|
|
|
* |
82
|
|
|
* @return \Illuminate\Http\Response |
83
|
|
|
*/ |
84
|
|
|
public function edit($slug) |
85
|
|
|
{ |
86
|
|
|
$page = Page::full($slug)->firstOrFail(); |
87
|
|
|
|
88
|
|
|
return $this->contentCrud->edit($page); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Update a page. |
93
|
|
|
* |
94
|
|
|
* @param \Illuminate\Http\Request $request Request data. |
95
|
|
|
* @param string $slug Slug of page to update. |
96
|
|
|
* |
97
|
|
|
* @return \Illuminate\Http\Response |
98
|
|
|
*/ |
99
|
|
|
public function update(Request $request, $slug) |
100
|
|
|
{ |
101
|
|
|
$page = Page::withTrashed()->where('slug', $slug)->firstOrFail(); |
|
|
|
|
102
|
|
|
|
103
|
|
|
return $this->contentCrud->update($request, $page, $this->user); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Remove a page from the portfolio. |
108
|
|
|
* |
109
|
|
|
* @param \Illuminate\Http\Request $request Request data. |
110
|
|
|
* @param string $slug Slug of page to remove. |
111
|
|
|
* |
112
|
|
|
* @return \Illuminate\Http\Response |
113
|
|
|
*/ |
114
|
|
|
public function destroy(Request $request, $slug) |
115
|
|
|
{ |
116
|
|
|
$page = Page::withTrashed()->where('slug', $slug)->firstOrFail(); |
|
|
|
|
117
|
|
|
|
118
|
|
|
return $this->contentCrud->destroy($request, $page, $this->user); |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..