Skip to content

Commit b7bc123

Browse files
author
Shawn McCool
committed
add the ability to edit your own thread
1 parent 07ec40f commit b7bc123

File tree

3 files changed

+47
-13
lines changed

3 files changed

+47
-13
lines changed

app/controllers/ForumController.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,36 @@ public function getEditThread($threadId)
103103

104104
$this->view('forum.editthread', compact('thread', 'tags'));
105105
}
106+
107+
public function postEditThread($threadId)
108+
{
109+
$comment = $this->comments->requireForumThreadById($threadId);
110+
111+
// i hate everything about these controllers, it's awful
112+
$form = $this->comments->getForumCreateForm();
113+
114+
if ( ! $form->isValid()) {
115+
return $this->redirectBack(['errors' => $form->getErrors()]);
116+
}
117+
118+
$comment->fill([
119+
'title' => Input::get('title'),
120+
'body' => Input::get('body'),
121+
]);
122+
123+
if ( ! $comment->isValid()) {
124+
return $this->redirectBack(['errors' => $comment->getErrors()]);
125+
}
126+
127+
$this->comments->save($comment);
128+
129+
// store tags
130+
$tags = $this->tags->getTagsByIds(Input::get('tags'));
131+
$comment->tags()->sync($tags->lists('id'));
132+
133+
// load new slug
134+
$commentSlug = $comment->slug()->first()->slug;
135+
136+
return $this->redirectAction('ForumController@getThread', [$commentSlug]);
137+
}
106138
}

app/routes.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
Route::get('forum/create-thread', ['before' => 'auth', 'uses' => 'ForumController@getCreateThread']);
4040
Route::post('forum/create-thread', ['before' => 'auth', 'uses' => 'ForumController@postCreateThread']);
4141
Route::get('forum/edit-thread/{threadId}', ['before' => 'auth', 'uses' => 'ForumController@getEditThread']);
42+
Route::post('forum/edit-thread/{threadId}', ['before' => 'auth', 'uses' => 'ForumController@postEditThread']);
4243
Route::get('forum/{slug}', ['before' => 'handle_slug', 'uses' => 'ForumController@getThread']);
4344
Route::post('forum/{slug}', ['before' => 'auth|handle_slug', 'uses' => 'ForumController@postThread']);
4445

app/views/forum/editthread.blade.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{{ Form::model($thread->resource) }}
2+
23
<fieldset>
34
<legend>Create Thread</legend>
45

@@ -20,19 +21,19 @@
2021
</div>
2122

2223
<div class="row">
23-
@if($tags->count() > 0)
24-
<h3>Describe your post with up to 3 tags</h3>
25-
{{ $errors->first('tags', '<small class="error">:message</small>') }}
26-
<ul class="tags">
27-
@foreach($tags as $tag)
28-
<li>
29-
<label>
30-
{{ Form::checkbox("tags[{$tag->id}]", $tag->id, isset($thread) ? $thread->hasTag($tag->id) : null) }} <span title="{{ $tag->description }}">{{ $tag->name }}</span>
31-
</label> - {{ $tag->description }}
32-
</li>
33-
@endforeach
34-
</ul>
35-
@endif
24+
@if($tags->count() > 0)
25+
<h3>Describe your post with up to 3 tags</h3>
26+
{{ $errors->first('tags', '<small class="error">:message</small>') }}
27+
<ul class="tags">
28+
@foreach($tags as $tag)
29+
<li>
30+
<label>
31+
{{ Form::checkbox("tags[{$tag->id}]", $tag->id, isset($thread) ? $thread->hasTag($tag->id) : null) }} <span title="{{ $tag->description }}">{{ $tag->name }}</span>
32+
</label> - {{ $tag->description }}
33+
</li>
34+
@endforeach
35+
</ul>
36+
@endif
3637
</div>
3738

3839
<div class="row">

0 commit comments

Comments
 (0)