Comment index action

This commit is contained in:
Alexander Yakovlev 2022-08-25 13:50:46 +07:00
parent a69887ab27
commit f418724bb8
Signed by: oreolek
GPG key ID: 8D24103F5EE2A6C0
3 changed files with 16 additions and 0 deletions

View file

@ -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
]);
}
}

View file

@ -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', '!=', '')

View file

@ -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">&nbsp;</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>