Browse Source
User can add and see comments on project detail
User can add and see comments on project detail
Add comment listing on project detail Add comment form Show comment list Latest comment on toppull/15/head
9 changed files with 216 additions and 0 deletions
-
50app/Http/Controllers/Projects/CommentsController.php
-
24resources/lang/de/comment.php
-
24resources/lang/en/comment.php
-
24resources/lang/id/comment.php
-
14resources/views/projects/comments.blade.php
-
18resources/views/projects/partials/comment-section.blade.php
-
3resources/views/projects/partials/nav-tabs.blade.php
-
6routes/web/projects.php
-
53tests/Feature/Projects/ProjectCommentsTest.php
@ -0,0 +1,50 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Http\Controllers\Projects; |
||||
|
|
||||
|
use Illuminate\Http\Request; |
||||
|
use App\Entities\Projects\Project; |
||||
|
use App\Http\Controllers\Controller; |
||||
|
|
||||
|
class CommentsController extends Controller |
||||
|
{ |
||||
|
/** |
||||
|
* Display a listing of the project comments. |
||||
|
* |
||||
|
* @param \App\Entities\Projects\Project $project |
||||
|
* @return \Illuminate\View\View |
||||
|
*/ |
||||
|
public function index(Project $project) |
||||
|
{ |
||||
|
$comments = $project->comments()->latest()->paginate(); |
||||
|
|
||||
|
return view('projects.comments', compact('project', 'comments')); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Store a new comment in storage. |
||||
|
* |
||||
|
* @param \Illuminate\Http\Request $request |
||||
|
* @param \App\Entities\Projects\Project $project |
||||
|
* @return \Illuminate\Http\RedirectResponse |
||||
|
*/ |
||||
|
public function store(Request $request, Project $project) |
||||
|
{ |
||||
|
$this->authorize('view', $project); |
||||
|
|
||||
|
$newComment = $request->validate([ |
||||
|
'body' => 'required|string|max:255', |
||||
|
'fu_type_id' => 'nullable|numeric', |
||||
|
'objection_id' => 'nullable|numeric', |
||||
|
]); |
||||
|
|
||||
|
$project->comments()->create([ |
||||
|
'body' => $newComment['body'], |
||||
|
'creator_id' => auth()->id(), |
||||
|
]); |
||||
|
|
||||
|
flash(__('comment.created'), 'success'); |
||||
|
|
||||
|
return back(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,24 @@ |
|||||
|
<?php |
||||
|
|
||||
|
return [ |
||||
|
// Labels
|
||||
|
'comment' => 'Comment', |
||||
|
'list' => 'Comments', |
||||
|
'empty' => 'Comment is empty.', |
||||
|
|
||||
|
// Actions
|
||||
|
'create' => 'Add Comment', |
||||
|
'create_text' => 'Write your comment ...', |
||||
|
'created' => 'Create new Comment succeded.', |
||||
|
'edit' => 'Edit Comment', |
||||
|
'update' => 'Update Comment', |
||||
|
'updated' => 'Update Comment succeded.', |
||||
|
'delete' => 'Delete Comment', |
||||
|
'delete_confirm' => 'Are you sure to delete this Comment?', |
||||
|
'deleted' => 'Delete Comment succeded.', |
||||
|
'undeleted' => 'Comment not deleted.', |
||||
|
'undeleteable' => 'Comment cannot be deleted.', |
||||
|
|
||||
|
// Attributes
|
||||
|
'body' => 'Comment', |
||||
|
]; |
||||
@ -0,0 +1,24 @@ |
|||||
|
<?php |
||||
|
|
||||
|
return [ |
||||
|
// Labels
|
||||
|
'comment' => 'Comment', |
||||
|
'list' => 'Comments', |
||||
|
'empty' => 'Comment is empty.', |
||||
|
|
||||
|
// Actions
|
||||
|
'create' => 'Add Comment', |
||||
|
'create_text' => 'Write your comment ...', |
||||
|
'created' => 'Create new Comment succeded.', |
||||
|
'edit' => 'Edit Comment', |
||||
|
'update' => 'Update Comment', |
||||
|
'updated' => 'Update Comment succeded.', |
||||
|
'delete' => 'Delete Comment', |
||||
|
'delete_confirm' => 'Are you sure to delete this Comment?', |
||||
|
'deleted' => 'Delete Comment succeded.', |
||||
|
'undeleted' => 'Comment not deleted.', |
||||
|
'undeleteable' => 'Comment cannot be deleted.', |
||||
|
|
||||
|
// Attributes
|
||||
|
'body' => 'Comment', |
||||
|
]; |
||||
@ -0,0 +1,24 @@ |
|||||
|
<?php |
||||
|
|
||||
|
return [ |
||||
|
// Labels
|
||||
|
'comment' => 'Komentar', |
||||
|
'list' => 'List Komentar', |
||||
|
'empty' => 'Belum ada Komentar', |
||||
|
|
||||
|
// Actions
|
||||
|
'create' => 'Tambah Komentar', |
||||
|
'create_text' => 'Tulis komentar anda ...', |
||||
|
'created' => 'Input Komentar berhasil.', |
||||
|
'edit' => 'Edit Komentar', |
||||
|
'update' => 'Update Komentar', |
||||
|
'updated' => 'Update data Komentar telah berhasil.', |
||||
|
'delete' => 'Hapus Komentar', |
||||
|
'delete_confirm' => 'Anda yakin akan menghapus Komentar ini?', |
||||
|
'deleted' => 'Hapus data Komentar telah berhasil.', |
||||
|
'undeleted' => 'Data Komentar gagal dihapus.', |
||||
|
'undeleteable' => 'Data Komentar tidak dapat dihapus.', |
||||
|
|
||||
|
// Attributes
|
||||
|
'body' => 'Komentar', |
||||
|
]; |
||||
@ -0,0 +1,14 @@ |
|||||
|
@extends('layouts.project') |
||||
|
|
||||
|
@section('subtitle', __('comment.list')) |
||||
|
|
||||
|
@section('content-project') |
||||
|
<div class="row"> |
||||
|
<div class="col-md-8 col-md-offset-1"> |
||||
|
{{ $comments->links() }} |
||||
|
@include('projects.partials.comment-section') |
||||
|
{{ $comments->links() }} |
||||
|
</div> |
||||
|
</div> |
||||
|
|
||||
|
@endsection |
||||
@ -0,0 +1,18 @@ |
|||||
|
{{ Form::open(['route' => ['projects.comments.store', $project]]) }} |
||||
|
<div class="row"> |
||||
|
<div class="col-md-9">{!! FormField::textarea('body', ['required' => true, 'label' => false, 'placeholder' => __('comment.create_text')]) !!}</div> |
||||
|
<div class="col-md-3"> |
||||
|
{{ Form::submit(__('comment.create'), ['class' => 'btn btn-success btn-block']) }}<br> |
||||
|
</div> |
||||
|
</div> |
||||
|
{{ Form::close() }} |
||||
|
@foreach($comments as $comment) |
||||
|
<div class="alert alert-warning"> |
||||
|
<legend style="font-size: 14px;margin-bottom: 10px;"> |
||||
|
<span class="label label-default pull-right">{{ $comment->created_at }}</span> |
||||
|
<strong>{{ $comment->creator->name }}</strong> |
||||
|
</legend> |
||||
|
|
||||
|
{!! nl2br($comment->body) !!} |
||||
|
</div> |
||||
|
@endforeach |
||||
@ -0,0 +1,53 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace Tests\Feature\Projects; |
||||
|
|
||||
|
use Tests\TestCase; |
||||
|
use App\Entities\Projects\Comment; |
||||
|
use App\Entities\Projects\Project; |
||||
|
use Illuminate\Foundation\Testing\DatabaseMigrations; |
||||
|
|
||||
|
class ProjectCommentsTest extends TestCase |
||||
|
{ |
||||
|
use DatabaseMigrations; |
||||
|
|
||||
|
/** @test */ |
||||
|
public function user_can_view_project_comments() |
||||
|
{ |
||||
|
$this->adminUserSigningIn(); |
||||
|
$project = factory(Project::class)->create(); |
||||
|
$comment = factory(Comment::class)->create([ |
||||
|
'commentable_type' => 'projects', |
||||
|
'commentable_id' => $project->id, |
||||
|
'body' => 'This is project comment.', |
||||
|
]); |
||||
|
|
||||
|
$this->visitRoute('projects.comments.index', $project); |
||||
|
$this->seeRouteIs('projects.comments.index', $project); |
||||
|
|
||||
|
$this->seeText('This is project comment.'); |
||||
|
} |
||||
|
|
||||
|
/** @test */ |
||||
|
public function admin_can_add_comment_to_a_project() |
||||
|
{ |
||||
|
$admin = $this->adminUserSigningIn(); |
||||
|
$project = factory(Project::class)->create(); |
||||
|
|
||||
|
$this->visitRoute('projects.comments.index', $project); |
||||
|
|
||||
|
$this->submitForm(__('comment.create'), [ |
||||
|
'body' => 'Komentar pertama.', |
||||
|
]); |
||||
|
|
||||
|
$this->seePageIs(route('projects.comments.index', $project)); |
||||
|
$this->see(__('comment.created')); |
||||
|
|
||||
|
$this->seeInDatabase('comments', [ |
||||
|
'commentable_type' => 'projects', |
||||
|
'commentable_id' => $project->id, |
||||
|
'body' => 'Komentar pertama.', |
||||
|
'creator_id' => $admin->id, |
||||
|
]); |
||||
|
} |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue