|
@@ -8,8 +8,55 @@
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
+use App\Http\Requests\StorePostRequest;
|
|
|
+use App\Post;
|
|
|
+use Illuminate\Http\Request;
|
|
|
|
|
|
-class PostsController
|
|
|
+class PostsController extends Controller
|
|
|
{
|
|
|
+ /**
|
|
|
+ * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
|
+ */
|
|
|
+ public function index()
|
|
|
+ {
|
|
|
+ $posts = Post::all();
|
|
|
|
|
|
-}
|
|
|
+ return view('posts.index', [
|
|
|
+ 'posts' => $posts,
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param Post $post
|
|
|
+ * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
|
+ */
|
|
|
+ public function view(Post $post)
|
|
|
+ {
|
|
|
+ return view('posts.view', [
|
|
|
+ 'post' => $post,
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param Post $post
|
|
|
+ * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
|
+ */
|
|
|
+ public function edit(Post $post)
|
|
|
+ {
|
|
|
+ return view('posts.edit', [
|
|
|
+ 'post' => $post,
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param Request $request
|
|
|
+ * @param Post $post
|
|
|
+ */
|
|
|
+ public function update(StorePostRequest $request, Post $post)
|
|
|
+ {
|
|
|
+ $post->fill($request->toArray());
|
|
|
+ $post->save();
|
|
|
+
|
|
|
+ return redirect(route('posts.index'));
|
|
|
+ }
|
|
|
+}
|