Browse Source

User can add comment to a project issue

pull/37/head
Nafies Luthfi 7 years ago
parent
commit
a0b7c66e40
  1. 34
      app/Http/Controllers/Issues/CommentController.php
  2. 6
      resources/views/projects/issues/partials/comment-section.blade.php
  3. 2
      resources/views/projects/issues/show.blade.php
  4. 5
      routes/web/projects.php
  5. 23
      tests/Feature/Projects/IssueCommentsTest.php

34
app/Http/Controllers/Issues/CommentController.php

@ -0,0 +1,34 @@
<?php
namespace App\Http\Controllers\Issues;
use Illuminate\Http\Request;
use App\Entities\Projects\Issue;
use App\Http\Controllers\Controller;
class CommentController extends Controller
{
/**
* Store a new comment in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Entities\Projects\Issue $issue
* @return \Illuminate\Http\RedirectResponse
*/
public function store(Request $request, Issue $issue)
{
$newComment = $request->validate([
'body' => 'required|string|max:255',
]);
$issue->comments()->create([
'body' => $newComment['body'],
'creator_id' => auth()->id(),
]);
flash(__('comment.created'), 'success');
return back();
}
}

6
resources/views/projects/issues/partials/comment-section.blade.php

@ -7,3 +7,9 @@
{!! nl2br($comment->body) !!}
</div>
@endforeach
{{ Form::open(['route' => ['issues.comments.store', $issue]]) }}
{!! FormField::textarea('body', ['required' => true, 'label' => false, 'placeholder' => __('comment.create_text')]) !!}
{{ Form::submit(__('comment.create'), ['class' => 'btn btn-success pull-right']) }}
{{ Form::close() }}
<div class="clearfix"></div><br>

2
resources/views/projects/issues/show.blade.php

@ -32,7 +32,7 @@
{{ link_to_route('projects.issues.index', __('issue.back_to_index'), [$project], ['class' => 'btn btn-default pull-right']) }}
</div>
</div>
<hr>
@include('projects.issues.partials.comment-section')
</div>
<div class="col-md-6">

5
routes/web/projects.php

@ -105,3 +105,8 @@ Route::group(['middleware' => ['auth']], function () {
* Issue Options Routes
*/
Route::patch('issues/{issue}/options', 'Issues\OptionController@update')->name('issues.options.update');
/**
* Issue Comments Routes
*/
Route::post('issues/{issue}/comments', 'Issues\CommentController@store')->name('issues.comments.store');

23
tests/Feature/Projects/IssueCommentsTest.php

@ -26,4 +26,27 @@ class IssueCommentsTest extends TestCase
$this->seeText('This is issue comment.');
}
/** @test */
public function admin_can_add_comment_to_an_issue()
{
$admin = $this->adminUserSigningIn();
$issue = factory(Issue::class)->create();
$this->visitRoute('projects.issues.show', [$issue->project, $issue]);
$this->submitForm(__('comment.create'), [
'body' => 'First comment.',
]);
$this->seePageIs(route('projects.issues.show', [$issue->project, $issue]));
$this->see(__('comment.created'));
$this->seeInDatabase('comments', [
'commentable_type' => 'issues',
'commentable_id' => $issue->id,
'body' => 'First comment.',
'creator_id' => $admin->id,
]);
}
}
Loading…
Cancel
Save