Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix comments #236

Merged
merged 1 commit into from May 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion app/Helpers/CommentHelper.php
Expand Up @@ -8,7 +8,6 @@ function getCommentLink(Comment $comment): string
$commentableResourceName = str_plural(strtolower(class_basename($comment->commentable_type)));
$commentableUrl = route("{$commentableResourceName}.show", $comment->commentable);
$commentUrl = "{$commentableUrl}#comment-{$comment->id}";

return $commentUrl;
}
}
25 changes: 17 additions & 8 deletions app/Http/Controllers/CommentController.php
Expand Up @@ -6,6 +6,8 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;

use function getCommentLink;

class CommentController extends Controller
{
public function __construct()
Expand Down Expand Up @@ -37,10 +39,10 @@ public function store(Request $request)
activity()
->performedOn($commentable)
->causedBy($user)
->withProperties(['comment' => $comment, 'url' => $this->getCommentUrl($comment)])
->withProperties(['comment' => $comment, 'url' => getCommentLink($comment)])
->log('commented');

return redirect($this->getCommentUrl($comment));
return redirect(getCommentLink($comment));
}

public function update(Request $request, Comment $comment)
Expand All @@ -54,9 +56,20 @@ public function update(Request $request, Comment $comment)
]
);
$content = $request->get('content', $comment->content);
$comment->update(['content' => $content]);
$comment->fill(['content' => $content]);

if ($comment->save()) {
flash()->success(__('layout.flash.success'));
}

return redirect(getCommentLink($comment));
}

return redirect($this->getCommentUrl($comment));
public function show(Comment $comment)
{
return redirect(
getCommentLink($comment)
);
}

public function destroy(Comment $comment)
Expand All @@ -65,8 +78,4 @@ public function destroy(Comment $comment)

return back();
}
private function getCommentUrl(Comment $comment)
{
return url()->previous() . '#comment-' . $comment->id;
}
}
2 changes: 2 additions & 0 deletions resources/views/components/comment/_modal.blade.php
Expand Up @@ -18,6 +18,8 @@
</button>
</div>
<div class="modal-body">
{!! Form::hidden('commentable_type', $comment->commentable_type) !!}
{!! Form::hidden('commentable_id', $comment->commentable_id) !!}
{!! Form::textarea('content', __('comment.update_comment_here'), $content)->attrs(['rows' => 3])->required() !!}
</div>
<div class="modal-footer text-left">
Expand Down
2 changes: 1 addition & 1 deletion resources/views/exercise/show.blade.php
Expand Up @@ -37,7 +37,7 @@
<p>{{ __('exercise.show.who_completed') }}</p>
<ul>
@foreach($exercise->users as $user)
<li>{{ $user->name }}</li>
<li><a href="{{ route('users.show', $user) }}">{{ $user->name }}</a></li>
@endforeach
</ul>
@endif
Expand Down
2 changes: 1 addition & 1 deletion routes/web.php
Expand Up @@ -34,5 +34,5 @@ static function () {
Route::resource('chapters', 'ChapterController')->only('index', 'show');
Route::resource('exercises', 'ExerciseController')->only('index', 'show');
Route::resource('log', 'ActivitylogController')->only('index');
Route::resource('comments', 'CommentController')->only('store', 'update', 'destroy');
Route::resource('comments', 'CommentController')->only('store', 'update', 'show', 'destroy');
});