FEATURE: add comments management

This commit is contained in:
Michal Kváček
2016-09-05 16:05:14 +02:00
parent 9ce9f62a45
commit 8f66a96ec0
12 changed files with 137 additions and 6 deletions
+8
View File
@@ -73,6 +73,14 @@ class GlobalViewDataProvider extends ServiceProvider
return preg_replace($pattern, $code, $view);
});
// shortcut for displaying Gravatar
Blade::extend(function ($view) {
$pattern = $this->createPattern('gravatar');
$code = '<?php echo \App\Helpers\Gravatar::img($2); ?>';
return preg_replace($pattern, $code, $view);
});
// shortcut for assets (placed in /public/assets/<theme>
Blade::extend(function ($view) {
$pattern = $this->createPattern('asset');
+2 -2
View File
@@ -16,11 +16,11 @@ class Comment extends Model
public function author()
{
return $this->belongsTo(User::class);
return $this->belongsTo(User::class, 'user_id');
}
public function article()
{
return $this->belongsTo(Content::class);
return $this->belongsTo(Content::class, 'content_id');
}
}
@@ -8,8 +8,12 @@ class CommentsOverview extends Controller
{
public function getOverview()
{
$comments = Comment::paginate(20);
$comments = Comment::with('article')
->with('author')
->orderBy('approved')
->orderBy('created_at', 'DESC')
->paginate(20);
dd($comments);
return view('article::admin/comments.overview', ['comments' => $comments]);
}
}
@@ -0,0 +1,33 @@
<?php
namespace Modules\Blog\Article\Http\Controllers\Admin;
use Modules\Blog\Article\Entities\Comment;
use Pingpong\Modules\Routing\Controller;
class EditComment extends Controller
{
public function approve($id)
{
$comment = Comment::findOrFail($id);
$comment->approved = 1;
$comment->save();
// Event::fire(ApprovedComment);
return redirect()
->back()
->with('success', trans('article::comments.approved'));
}
public function delete($id)
{
$comment = Comment::findOrFail($id);
$comment->delete();
// Event::fire(DeletedComment);
return redirect()
->back()
->with('success', trans('article::comments.deleted'));
}
}
+8 -2
View File
@@ -2,13 +2,19 @@
// routes for comments
Route::group([
'middleware' => ['web', 'auth'],
'prefix' => 'comments',
'middleware' => ['web', 'auth', 'adminMenu'],
'prefix' => 'admin/comments',
'namespace' => 'Modules\Blog\Article\Http\Controllers\Admin'
], function () {
Route::get('/', 'CommentsOverview@getOverview')
->name('comments.overview');
Route::get('/delete/{id}', 'EditComment@delete')
->name('comments.delete');
Route::get('/approve/{id}', 'EditComment@approve')
->name('comments.approve');
});
Route::group([
@@ -0,0 +1,8 @@
<?php
return [
'createdAt' => 'Created at :date',
'commentedArticle' => 'Article',
'approve' => 'Approve comment',
'approved' => 'Comment successfully approved',
'deleted' => 'Comment deleted'
];
@@ -0,0 +1,68 @@
@extends('admin.layoutWithNavigation')
@section('pageHeading', trans('article::module.comments'))
@section('content')
@if (count($comments))
@foreach($comments as $comment)
<div class="card @if(!$comment->approved) card-warning @else card-default @endif">
<div class="card-header">
<div class="header-block">
<p class="title">
<img src="@gravatar($comment->author->email, 25)" class="img-rounded" alt="">
{{$comment->author->name}} ({{$comment->author->email}})
</p>
</div>
</div>
<div class="card-block">
<p>
{{$comment->content}}
</p>
</div>
<div class="card-footer">
@lang('article::comments.createdAt', ['date' => \App\Helpers\Template::date($comment->created_at)]) |
@lang('article::comments.commentedArticle'): <a href="{{route('page.content', ['url' => $comment->article->url])}}" target="_blank">
{{$comment->article->title}}
</a>
<div class="pull-right">
@if (!$comment->approved)
<a href="{{route('comments.approve', ['id' => $comment->id])}}" class="btn btn-sm btn-success" title="@lang('article::comments.approve')"
data-toggle="tooltip"><i class="fa fa-fw fa-check"></i></a>
@endif
<a href="{{route('comments.delete', ['id' => $comment->id])}}" class="btn btn-sm btn-warning"><i class="fa fa-fw fa-trash"></i></a>
</div>
</div>
</div>
{{--<div class="comment row">--}}
{{--<div class="col-lg-2">--}}
{{--<img class="img-rounded" src="@gravatar($comment->author->email)" alt="">--}}
{{--{{$comment->author->name}}--}}
{{--@date($comment->created_at)--}}
{{--</div>--}}
{{--<div class="col-lg-10">{{$comment->content}}</div>--}}
{{--<div class="col-lg2">--}}
{{--</div>--}}
{{--</div>--}}
@endforeach
@else
<div class="alert alert-info">
@lang('article::comments.noComments')
</div>
@endif
@endsection
+4
View File
@@ -14363,4 +14363,8 @@ img {
.pagination li {
display: inline;
padding: .5em;
}
.header-block img {
margin-right: 10px;
}