Comment index

This commit is contained in:
Alexander Yakovlev 2022-08-19 11:24:05 +07:00
parent 0f4d2eba50
commit 947eae37e4
Signed by: oreolek
GPG key ID: 8D24103F5EE2A6C0
5 changed files with 64 additions and 39 deletions

View file

@ -2,14 +2,18 @@
namespace App\Http\Controllers;
use App\Models\Post;
use App\Models\Comment;
class CommentController extends Controller
{
public function load() {
public function index() {
$pages = Comment::orderBy('posted_at', 'DESC')->simplePaginate(15);
return view('comment.index', [
'items' => $pages
]);
}
public function post($id) {
$post = Post::findOrFail($id);
public function view($id) {
$comment = Comment::findOrFail($id);
}
}

View file

@ -8,4 +8,11 @@ use Illuminate\Database\Eloquent\Model;
class Comment extends Model
{
use HasFactory;
public function scopePublished($query) {
return $query
->where('content', '!=', '')
->where('posted_at', '<', date('Y-m-d H:i:s'))
->where('is_approved', 1);
}
}

View file

@ -0,0 +1,42 @@
@extends('_layouts.app')
@section('content')
<table class="table table-striped table-hover">
<thead>
<tr>
<th class="col-md-9">Текст</th>
<th class="col-md-1">Meta</th>
<th class="col-md-1">OK?</th>
<th class="col-md-1">&nbsp;</th>
</tr>
</thead>
<tbody>
@foreach($items as $item)
<tr>
<td>
{!! $item['content'] !!}
</td>
<td>
<div class="date">{{$item['date']}}</div>
<div class="text-primary">
@if (isset($item['author_email']))
<a class="author" href="mailto:{{ $item['author_email']}}">
{{ $item['author_email'] }}
@endif
{{ $item['author_name'] }}
@if (isset($item['author_email']))
</a>
@endif
</div>
</td>
<td>{{{$item['is_approved']}}}</td>
<td>
<a class="btn" href="{!! $item['post_link'] !!}#comment_{{$item['comment_id']}}"><i class="fa fa-link"></i></a>
<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>
</tr>
@endforeach
</tbody>
</table>
@endsection

View file

@ -1,29 +0,0 @@
<table class="table table-striped table-hover">
<thead>
<tr>
<th class="col-md-9">Текст</th>
<th class="col-md-1">Meta</th>
<th class="col-md-1">OK?</th>
<th class="col-md-1">&nbsp;</th>
</tr>
</thead>
<tbody>
{{#get_items}}
<tr>
<td>{{{content}}}</td>
<td>
<div class="date">{{date}}</div>
<div class="text-primary">
{{#author_email}}<a class="author" href="mailto:{{author_email}}">{{/author_email}} {{author_name}} {{#author_email}}</a>{{/author_email}}
</div>
</td>
<td>{{{is_approved}}}</td>
<td>
<a class="btn" href="{{post_link}}#comment_{{comment_id}}"><i class="fa fa-link"></i></a>
<a class="btn" href="{{edit_link}}"><i class="fa fa-pencil-square-o"></i></a>
<a class="btn" href="{{delete_link}}"><i class="fa fa-times"></i></a>
</td>
</tr>
{{/get_items}}
</tbody>
</table>

View file

@ -18,10 +18,10 @@ use App\Http\Controllers\CommentController;
require __DIR__.'/auth.php';
Route::controller(PostController::class)->group(function() {
Route::get('/', 'read');
Route::get('/Post/read', 'read')->name('post.read');
Route::any('/Post/read/page/{page}', 'read');
Route::get('/Post/view/{id}', 'view')->name('view');
Route::get('/', 'read')->name('default');
Route::get('/post/read', 'read')->name('post.read');
Route::any('/post/read/page/{page}', 'read');
Route::get('/post/view/{id}', 'view')->name('view');
Route::get('/post/edit/{id}', 'edit')->name('post.edit');
Route::get('/{id}', 'view');
});
@ -32,6 +32,7 @@ Route::controller(PageController::class)->group(function() {
});
// Route::get('/Tag/{id}', [PostController::class, 'view'])->name('tag');
Route::controller(CommentController::class)->group(function() {
Route::any('/Comment/post/{id}', 'load')->name('comments.load');
Route::post('/Comment/post', 'post')->name('comments.post');
Route::get('/comment/index', 'index')->name('comments.index');
Route::any('/comment/post/{id}', 'load')->name('comments.load');
Route::post('/comment/post', 'post')->name('comments.post');
});