@@ -99,14 +99,16 @@ public function postCreateThread()
9999 public function getEditThread ($ threadId )
100100 {
101101 $ thread = $ this ->comments ->requireForumThreadById ($ threadId );
102- $ tags = $ this -> tags -> getAllForForum ( );
102+ if (Auth:: user ()-> id ! = $ thread -> author_id ) return Redirect:: to ( ' / ' );
103103
104+ $ tags = $ this ->tags ->getAllForForum ();
104105 $ this ->view ('forum.editthread ' , compact ('thread ' , 'tags ' ));
105106 }
106107
107108 public function postEditThread ($ threadId )
108109 {
109- $ comment = $ this ->comments ->requireForumThreadById ($ threadId );
110+ $ thread = $ this ->comments ->requireForumThreadById ($ threadId );
111+ if (Auth::user ()->id != $ thread ->author_id ) return Redirect::to ('/ ' );
110112
111113 // i hate everything about these controllers, it's awful
112114 $ form = $ this ->comments ->getForumCreateForm ();
@@ -115,24 +117,54 @@ public function postEditThread($threadId)
115117 return $ this ->redirectBack (['errors ' => $ form ->getErrors ()]);
116118 }
117119
118- $ comment ->fill ([
120+ $ thread ->fill ([
119121 'title ' => Input::get ('title ' ),
120122 'body ' => Input::get ('body ' ),
121123 ]);
122124
123- if ( ! $ comment ->isValid ()) {
124- return $ this ->redirectBack (['errors ' => $ comment ->getErrors ()]);
125+ if ( ! $ thread ->isValid ()) {
126+ return $ this ->redirectBack (['errors ' => $ thread ->getErrors ()]);
125127 }
126128
127- $ this ->comments ->save ($ comment );
129+ $ this ->comments ->save ($ thread );
128130
129131 // store tags
130132 $ tags = $ this ->tags ->getTagsByIds (Input::get ('tags ' ));
131- $ comment ->tags ()->sync ($ tags ->lists ('id ' ));
133+ $ thread ->tags ()->sync ($ tags ->lists ('id ' ));
132134
133135 // load new slug
134- $ commentSlug = $ comment ->slug ()->first ()->slug ;
136+ $ threadSlug = $ thread ->slug ()->first ()->slug ;
135137
136- return $ this ->redirectAction ('ForumController@getThread ' , [$ commentSlug ]);
138+ return $ this ->redirectAction ('ForumController@getThread ' , [$ threadSlug ]);
139+ }
140+
141+ // oh god it's so bad
142+ public function getEditComment ($ commentId )
143+ {
144+ $ comment = $ this ->comments ->requireForumThreadById ($ commentId );
145+ if (Auth::user ()->id != $ comment ->author_id ) return Redirect::to ('/ ' );
146+ $ this ->view ('forum.editcomment ' , compact ('comment ' ));
147+ }
148+
149+ public function postEditComment ($ commentId )
150+ {
151+ $ comment = $ this ->comments ->requireForumThreadById ($ commentId );
152+ if (Auth::user ()->id != $ comment ->author_id ) return Redirect::to ('/ ' );
153+
154+ // i hate everything about these controllers, it's awful
155+ $ form = $ this ->comments ->getForumReplyForm ();
156+
157+ if ( ! $ form ->isValid ()) return $ this ->redirectBack (['errors ' => $ form ->getErrors ()]);
158+
159+ $ comment ->fill ([
160+ 'title ' => Input::get ('title ' ),
161+ 'body ' => Input::get ('body ' ),
162+ ]);
163+
164+ if ( ! $ comment ->isValid ()) return $ this ->redirectBack (['errors ' => $ comment ->getErrors ()]);
165+
166+ $ this ->comments ->save ($ comment );
167+
168+ return $ this ->redirectAction ('ForumController@getThread ' , [$ comment ->parent ->slug ->slug ]);
137169 }
138170}
0 commit comments