4
4
5
5
use Artesaos \SEOTools \Facades \OpenGraph ;
6
6
use Artesaos \SEOTools \Facades \SEOMeta ;
7
+ use Chriscreates \Blog \Category ;
7
8
use Chriscreates \Blog \Post ;
8
9
use Chriscreates \Blog \Requests \ValidatePostRequest ;
10
+ use Chriscreates \Blog \Tag ;
11
+ use Illuminate \Http \JsonResponse ;
9
12
use Illuminate \Http \Request ;
10
13
use Illuminate \Support \Facades \Storage ;
11
14
@@ -42,16 +45,22 @@ public function index()
42
45
*/
43
46
public function create ()
44
47
{
45
- return view ('admin.posts.create-post ' );
48
+ $ post = new Post ;
49
+
50
+ return view ('admin.posts.edit-post ' , [
51
+ 'post ' => $ post ,
52
+ 'categories ' => Category::all (),
53
+ 'tags ' => Tag::all (),
54
+ ]);
46
55
}
47
56
48
57
/**
49
58
* Store a newly created resource in storage.
50
59
*
51
- * @param \App\Http \Requests\ValidatePostRequest $request
52
- * @return \Illuminate\Http\Response
60
+ * @param \Chriscreates\Blog \Requests\ValidatePostRequest $request
61
+ * @return \Illuminate\Http\JsonResponse
53
62
*/
54
- public function store (ValidatePostRequest $ request )
63
+ public function store (ValidatePostRequest $ request ) : JsonResponse
55
64
{
56
65
$ post = Post::create ($ request ->only ([
57
66
'title ' ,
@@ -64,9 +73,7 @@ public function store(ValidatePostRequest $request)
64
73
'allow_guest_comments ' ,
65
74
]));
66
75
67
- return redirect ()
68
- ->route ('posts.edit ' , ['post ' => $ post ->id ])
69
- ->with ('success ' , 'Post created. ' );
76
+ return response ()->json ($ post );
70
77
}
71
78
72
79
/**
@@ -98,17 +105,23 @@ public function show(Post $post)
98
105
*/
99
106
public function edit (Post $ post )
100
107
{
101
- return view ('admin.posts.edit-post ' , compact ('post ' ));
108
+ $ post ->load ('category ' , 'tags ' );
109
+
110
+ return view ('admin.posts.edit-post ' , [
111
+ 'post ' => $ post ,
112
+ 'categories ' => Category::all (),
113
+ 'tags ' => Tag::all (),
114
+ ]);
102
115
}
103
116
104
117
/**
105
118
* Update the specified resource in storage.
106
119
*
107
- * @param \App\Http \Requests\ValidatePostRequest $request
120
+ * @param \Chriscreates\Blog \Requests\ValidatePostRequest $request
108
121
* @param \Chriscreates\Blog\Post $post
109
- * @return \Illuminate\Http\Response
122
+ * @return \Illuminate\Http\JsonResponse
110
123
*/
111
- public function update (ValidatePostRequest $ request , Post $ post )
124
+ public function update (ValidatePostRequest $ request , Post $ post ) : JsonResponse
112
125
{
113
126
$ post ->update ($ request ->only ([
114
127
'title ' ,
@@ -121,23 +134,23 @@ public function update(ValidatePostRequest $request, Post $post)
121
134
'allow_guest_comments ' ,
122
135
]));
123
136
124
- return redirect ()
125
- -> route ( ' posts.edit ' , [ ' post ' => $ post -> id ])
126
- -> with ( ' success ' , ' Post updated. ' );
137
+ $ post -> refresh ();
138
+
139
+ return response ()-> json ( $ post );
127
140
}
128
141
129
142
/**
130
143
* Remove the specified resource from storage.
131
144
*
132
145
* @param \Chriscreates\Blog\Post $post
133
- * @return \Illuminate\Http\Response
146
+ * @return \Illuminate\Http\JsonResponse
134
147
*/
135
- public function destroy (Post $ post )
148
+ public function destroy (Post $ post ) : JsonResponse
136
149
{
137
150
$ post ->delete ();
138
151
139
- return redirect ()
140
- -> route ( ' posts.index ' )
141
- -> with ( ' success ' , ' Post deleted. ' );
152
+ $ post = new Post ;
153
+
154
+ return response ()-> json ( $ post );
142
155
}
143
156
}
0 commit comments