comment form

This commit is contained in:
Alexander Yakovlev 2022-08-27 07:07:09 +07:00
parent 6fff584f59
commit d9834efa4f
Signed by: oreolek
GPG key ID: 8D24103F5EE2A6C0
12 changed files with 91 additions and 27 deletions

View file

@ -12,15 +12,27 @@ class CommentController extends Controller
$pages = Comment::orderBy('posted_at', 'DESC')->simplePaginate(15);
return view('comment.index', [
'items' => $pages,
'is_ajax' => $request->isXmlHttpRequest(),
]);
}
public function load($id, Request $request) {
$post = Post::findOrFail($id);
$comments= $post->comments()->published()->get();
$is_ajax = $request->isXmlHttpRequest();
if ($is_ajax) {
return view('comment.ajaxlist', [
'items' => $comments,
'is_ajax' => $is_ajax,
]);
}
return view('comment.index', [
'items' => $comments,
'is_ajax' => $request->isXmlHttpRequest(),
'is_ajax' => $is_ajax,
]);
}
public function post($id) {
return view('comment.form', [
'post_id' => $id
]);
}
}

View file

@ -115,7 +115,7 @@ class ViewComposer extends GenericView
$view->with('tags', $this->get_tags());
$view->with('id', $this->item->id);
$view->with('load_comments_action', route('comments.load', $this->item->id));
$view->with('load_comment_form_action', route('comments.post'));
$view->with('load_comment_form_action', route('comments.post', $this->item->id ));
$view->with('navigation', $this->navigation());
}

View file

@ -18,5 +18,6 @@ class ViewServiceProvider extends ServiceProvider
View::composer('read', 'App\Http\View\ReadComposer');
View::composer('single', 'App\Http\View\ViewComposer');
View::composer('comment.index', 'App\Http\View\CommentIndexComposer');
View::composer('comment.ajaxlist', 'App\Http\View\CommentIndexComposer');
}
}

View file

@ -12,7 +12,6 @@
</head>
<body vocab="http://schema.org">
<div class = "main_content">
{!! $breadcrumbs ?? ''!!}
@if(!empty($title))
<h1>{{ $title }}</h1>
@endif

View file

@ -16,7 +16,7 @@
<ul class="dropdown-menu">
@foreach($navigation['dropdown']['links'] as $link)
<li class="nav-item">
<a href="{{ $link['link'] }}" class="nav-link">
<a href="/{{ $link['link'] }}" class="nav-link">
{{ $link['text'] }}
</a>
</li>
@ -25,7 +25,7 @@
</li>
@foreach($navigation['links'] as $link)
<li class="nav-item">
<a href="{{ $link['link'] }}" class="nav-link">
<a href="/{{ $link['link'] }}" class="nav-link">
{{ $link['text'] }}
</a>
</li>

View file

@ -0,0 +1,27 @@
@extends('_layouts.empty')
@section('content')
<table class="table table-striped table-hover">
<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']}}">
@endif
{{ $item['author_name'] }}
@if (isset($item['author_email']))
</a>
@endif
</div>
</td>
</tr>
@endforeach
</tbody>
</table>
@endsection

View file

@ -0,0 +1,13 @@
<form method="POST" action="{{ route('comments.post', ['id' => $post_id]) }}">
@csrf
{{-- Honeytrap inputs - if you type something there, you have form autofill --}}
<input type="hidden" name="email">
<input type="hidden" name="title">
<input type="hidden" name="name">
<input type="hidden" name="post_id" value="{{ $post_id }}">
<x-textfield name="author_name" label="Ваша подпись (имя)"></x-textfield>
<x-textfield name="author_email" label="E-mail для обратной связи"></x-textfield>
<x-textarea name="content" label="Комментарий"></x-textfield>
<button type="submit" class="btn btn-primary">Отправить</button>
</form>

View file

@ -1,12 +0,0 @@
<form method="POST" action="{{url}}">
<input type="hidden" name="email">
<input type="hidden" name="title">
<input type="hidden" name="name">
<input type="hidden" name="post_id" value="-ID-">
{{#inputs}}
{{{author_name}}}
{{{author_email}}}
{{{content}}}
{{/inputs}}
<input type="submit" class="btn btn-primary" value="Отправить">
</form>

View file

@ -1,12 +1,8 @@
@if (!$is_ajax)
@extends('_layouts.app')
@else
@extends('_layouts.empty')
@endif
@extends('_layouts.app')
@section('content')
<table class="table table-striped table-hover">
@if (!$is_ajax && $is_admin)
@if ($is_admin)
<thead>
<tr>
<th class="col-md-9">Текст</th>
@ -34,7 +30,7 @@
@endif
</div>
</td>
@if (!$is_ajax && $is_admin)
@if ($is_admin)
<td>
@if ($item['is_approved'] === \App\Models\Comment::STATUS_APPROVED)
<span class="fa fa-check-square-o"></span> одобрен

View file

@ -0,0 +1,14 @@
@props([
'disabled' => false,
'type' => 'text',
'value' => '',
'label' => 'Label here',
'name' => 'textfield',
])
<div class="row mb-3">
<label for="{{ $name }}" class="col-sm-2 col-form-label">{{ $label }}</label>
<div class="col-sm-10">
<textarea rows=3 id="input-{{ $name }}" {{ $disabled ? 'disabled' : '' }} {!! $attributes->merge(['class' => 'form-control']) !!}></textarea>
</div>
</div>

View file

@ -0,0 +1,14 @@
@props([
'disabled' => false,
'type' => 'text',
'value' => '',
'label' => 'Label here',
'name' => 'textfield',
])
<div class="row mb-3">
<label for="{{ $name }}" class="col-sm-2 col-form-label">{{ $label }}</label>
<div class="col-sm-10">
<input id="input-{{ $name }}" {{ $disabled ? 'disabled' : '' }} {!! $attributes->merge(['class' => 'form-control']) !!}>
</div>
</div>

View file

@ -36,8 +36,8 @@ Route::controller(TagController::class)->group(function() {
});
Route::controller(CommentController::class)->group(function() {
Route::get('/comment/index', 'index')->name('comments.index');
Route::any('/comment/post/{id}', 'load')->name('comments.load');
Route::any('/comment/load/{id}', 'load')->name('comments.load');
Route::any('/comment/edit/{id}', 'edit')->name('comments.edit');
Route::any('/comment/delete/{id}', 'delete')->name('comments.delete');
Route::get('/comment/post', 'post')->name('comments.post');
Route::any('/comment/post/{id}', 'post')->name('comments.post');
});