1 | <?php namespace Arcanesoft\Blog\Http\Controllers\Admin; |
||
17 | class PostsController extends Controller |
||
18 | { |
||
19 | /* ----------------------------------------------------------------- |
||
20 | | Properties |
||
21 | | ----------------------------------------------------------------- |
||
22 | */ |
||
23 | |||
24 | /** |
||
25 | * The post model. |
||
26 | * |
||
27 | * @var \Arcanesoft\Blog\Models\Post |
||
28 | */ |
||
29 | private $post; |
||
30 | |||
31 | /* ----------------------------------------------------------------- |
||
32 | | Constructor |
||
33 | | ----------------------------------------------------------------- |
||
34 | */ |
||
35 | |||
36 | /** |
||
37 | * PostsController constructor. |
||
38 | * |
||
39 | * @param \Arcanesoft\Blog\Models\Post $post |
||
40 | */ |
||
41 | public function __construct(Post $post) |
||
42 | { |
||
43 | parent::__construct(); |
||
44 | |||
45 | $this->post = $post; |
||
46 | |||
47 | $this->setCurrentPage('blog-posts'); |
||
48 | $this->addBreadcrumbRoute(trans('blog::posts.titles.posts'), 'admin::blog.posts.index'); |
||
49 | } |
||
50 | |||
51 | /* ----------------------------------------------------------------- |
||
52 | | Main Methods |
||
53 | | ----------------------------------------------------------------- |
||
54 | */ |
||
55 | |||
56 | /** |
||
57 | * List the posts. |
||
58 | * |
||
59 | * @param bool $trashed |
||
60 | * |
||
61 | * @return \Illuminate\View\View |
||
62 | */ |
||
63 | public function index($trashed = false) |
||
64 | { |
||
65 | $this->authorize(PostsPolicy::PERMISSION_LIST); |
||
66 | |||
67 | $posts = $this->post->with(['author', 'category'])->when($trashed, function ($query) { |
||
|
|||
68 | return $query->onlyTrashed(); |
||
69 | })->paginate(30); |
||
70 | |||
71 | $title = trans('blog::posts.titles.posts-list'); |
||
72 | $this->setTitle($title . ($trashed ? ' - '.trans('core::generals.trashed') : '')); |
||
73 | $this->addBreadcrumb($title); |
||
74 | |||
75 | return $this->view('admin.posts.index', compact('trashed', 'posts')); |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * List the trashed posts. |
||
80 | * |
||
81 | * @return \Illuminate\View\View |
||
82 | */ |
||
83 | public function trash() |
||
84 | { |
||
85 | return $this->index(true); |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * Create a post. |
||
90 | * |
||
91 | * @return \Illuminate\View\View |
||
92 | */ |
||
93 | public function create() |
||
94 | { |
||
95 | $this->authorize(PostsPolicy::PERMISSION_CREATE); |
||
96 | |||
97 | $categories = Category::getSelectData(); |
||
98 | $tags = Tag::getSelectData(); |
||
99 | $statuses = Post::getStatuses(); |
||
100 | |||
101 | $this->setTitle($title = trans('blog::posts.titles.create-post')); |
||
102 | $this->addBreadcrumb($title); |
||
103 | |||
104 | return $this->view('admin.posts.create', compact('categories', 'tags', 'statuses')); |
||
105 | } |
||
106 | |||
107 | /** |
||
108 | * Store the post. |
||
109 | * |
||
110 | * @param \Arcanesoft\Blog\Http\Requests\Admin\Posts\CreatePostRequest $request |
||
111 | * |
||
112 | * @return \Illuminate\Http\RedirectResponse |
||
113 | */ |
||
114 | public function store(CreatePostRequest $request) |
||
115 | { |
||
116 | $this->authorize(PostsPolicy::PERMISSION_CREATE); |
||
117 | |||
118 | $post = Post::createOne($request->getValidatedData()); |
||
119 | |||
120 | $this->transNotification('created', ['title' => $post->title], $post->toArray()); |
||
121 | |||
122 | return redirect()->route('admin::blog.posts.show', [$post]); |
||
123 | } |
||
124 | |||
125 | /** |
||
126 | * Show a post. |
||
127 | * |
||
128 | * @param \Arcanesoft\Blog\Models\Post $post |
||
129 | * |
||
130 | * @return \Illuminate\View\View |
||
131 | */ |
||
132 | public function show(Post $post) |
||
143 | |||
144 | /** |
||
145 | * Edit a post. |
||
146 | * |
||
147 | * @param \Arcanesoft\Blog\Models\Post $post |
||
148 | * |
||
149 | * @return \Illuminate\View\View |
||
150 | */ |
||
151 | public function edit(Post $post) |
||
164 | |||
165 | /** |
||
166 | * Update the post. |
||
167 | * |
||
168 | * @param \Arcanesoft\Blog\Models\Post $post |
||
169 | * @param \Arcanesoft\Blog\Http\Requests\Admin\Posts\UpdatePostRequest $request |
||
170 | * |
||
171 | * @return \Illuminate\Http\RedirectResponse |
||
172 | */ |
||
173 | public function update(Post $post, UpdatePostRequest $request) |
||
183 | |||
184 | /** |
||
185 | * Publish/Unpublish a post. |
||
186 | * |
||
187 | * @param \Arcanesoft\Blog\Models\Post $post |
||
188 | * |
||
189 | * @return \Illuminate\Http\JsonResponse |
||
190 | */ |
||
191 | public function publish(Post $post) |
||
197 | |||
198 | /** |
||
199 | * Restore a trashed post. |
||
200 | * |
||
201 | * @param \Arcanesoft\Blog\Models\Post $post |
||
202 | * |
||
203 | * @return \Illuminate\Http\JsonResponse |
||
204 | */ |
||
205 | public function restore(Post $post) |
||
220 | |||
221 | /** |
||
222 | * Delete a post. |
||
223 | * |
||
224 | * @param \Arcanesoft\Blog\Models\Post $post |
||
225 | * |
||
226 | * @return \Illuminate\Http\JsonResponse |
||
227 | */ |
||
228 | public function delete(Post $post) |
||
243 | |||
244 | /* ----------------------------------------------------------------- |
||
245 | | Other Methods |
||
246 | | ----------------------------------------------------------------- |
||
247 | */ |
||
248 | |||
249 | /** |
||
250 | * Notify with translation. |
||
251 | * |
||
252 | * @todo: Refactor this methods to the core package ? |
||
253 | * |
||
254 | * @param string $action |
||
255 | * @param array $replace |
||
256 | * @param array $context |
||
257 | * |
||
258 | * @return string |
||
259 | */ |
||
260 | protected function transNotification($action, array $replace = [], array $context = []) |
||
270 | } |
||
271 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: