comment form
This commit is contained in:
parent
6fff584f59
commit
d9834efa4f
|
@ -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
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
</head>
|
||||
<body vocab="http://schema.org">
|
||||
<div class = "main_content">
|
||||
{!! $breadcrumbs ?? ''!!}
|
||||
@if(!empty($title))
|
||||
<h1>{{ $title }}</h1>
|
||||
@endif
|
||||
|
|
|
@ -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>
|
||||
|
|
27
resources/views/comment/ajaxlist.blade.php
Normal file
27
resources/views/comment/ajaxlist.blade.php
Normal 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
|
13
resources/views/comment/form.blade.php
Normal file
13
resources/views/comment/form.blade.php
Normal 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>
|
|
@ -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>
|
|
@ -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> одобрен
|
||||
|
|
14
resources/views/components/textarea.blade.php
Normal file
14
resources/views/components/textarea.blade.php
Normal 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>
|
14
resources/views/components/textfield.blade.php
Normal file
14
resources/views/components/textfield.blade.php
Normal 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>
|
|
@ -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');
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue