Comment index action
This commit is contained in:
parent
a69887ab27
commit
f418724bb8
|
@ -3,6 +3,7 @@
|
|||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Comment;
|
||||
use App\Models\Post;
|
||||
|
||||
class CommentController extends Controller
|
||||
{
|
||||
|
@ -12,4 +13,11 @@ class CommentController extends Controller
|
|||
'items' => $pages
|
||||
]);
|
||||
}
|
||||
public function load($id) {
|
||||
$post = Post::findOrFail($id);
|
||||
$comments= $post->comments()->published()->get();
|
||||
return view('comment.index', [
|
||||
'items' => $comments
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,10 @@ class Post extends Model
|
|||
return $this->belongsToMany('App\Models\Tag', 'posts_tags');
|
||||
}
|
||||
|
||||
public function comments() {
|
||||
return $this->belongsTo('App\Models\Comment');
|
||||
}
|
||||
|
||||
public function scopePublished($query) {
|
||||
return $query
|
||||
->where('content', '!=', '')
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
@section('content')
|
||||
<table class="table table-striped table-hover">
|
||||
@if ($is_admin)
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="col-md-9">Текст</th>
|
||||
|
@ -10,6 +11,7 @@
|
|||
<th class="col-md-1"> </th>
|
||||
</tr>
|
||||
</thead>
|
||||
@endif
|
||||
<tbody>
|
||||
@foreach($items as $item)
|
||||
<tr>
|
||||
|
@ -28,6 +30,7 @@
|
|||
@endif
|
||||
</div>
|
||||
</td>
|
||||
@if ($is_admin)
|
||||
<td>
|
||||
@if ($item['is_approved'] === \App\Models\Comment::STATUS_APPROVED)
|
||||
<span class="fa fa-check-square-o"></span> одобрен
|
||||
|
@ -42,6 +45,7 @@
|
|||
<a class="btn" href="{!! $item['edit_link'] !!}"><i class="fa fa-pencil-square-o"></i></a>
|
||||
<a class="btn" href="{!! $item['delete_link'] !!}"><i class="fa fa-times"></i></a>
|
||||
</td>
|
||||
@endif
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
|
|
Loading…
Reference in a new issue