mirror of https://github.com/4xmen/xshop.git
added comment controller
parent
494c642956
commit
58bc5e97d1
@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\XController;
|
||||
use App\Http\Requests\CommentSaveRequest;
|
||||
use App\Models\Access;
|
||||
use App\Models\Comment;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Helper;
|
||||
use function App\Helpers\hasCreateRoute;
|
||||
|
||||
class CommentController extends XController
|
||||
{
|
||||
|
||||
// protected $_MODEL_ = Comment::class;
|
||||
// protected $SAVE_REQUEST = CommentSaveRequest::class;
|
||||
|
||||
protected $cols = ['*'];
|
||||
protected $extra_cols = [];
|
||||
|
||||
protected $searchable = ['body','name','email','ip'];
|
||||
|
||||
protected $listView = 'admin.comments.comment-list';
|
||||
protected $formView = 'admin.comments.comment-form';
|
||||
|
||||
|
||||
protected $buttons = [
|
||||
// 'edit' =>
|
||||
// ['title' => "Edit", 'class' => 'btn-outline-primary', 'icon' => 'ri-edit-2-line'],
|
||||
// 'show' =>
|
||||
// ['title' => "Detail", 'class' => 'btn-outline-light', 'icon' => 'ri-eye-line'],
|
||||
// 'destroy' =>
|
||||
// ['title' => "Remove", 'class' => 'btn-outline-danger delete-confirm', 'icon' => 'ri-close-line'],
|
||||
];
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(Comment::class, CommentSaveRequest::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $comment Comment
|
||||
* @param $request CommentSaveRequest
|
||||
* @return Comment
|
||||
*/
|
||||
public function save($comment, $request)
|
||||
{
|
||||
|
||||
$comment->save();
|
||||
return $comment;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
return view($this->formView);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(Comment $item)
|
||||
{
|
||||
//
|
||||
return view($this->formView, compact('item'));
|
||||
}
|
||||
|
||||
public function bulk(Request $request)
|
||||
{
|
||||
|
||||
// dd($request->all());
|
||||
$data = explode('.', $request->input('action'));
|
||||
$action = $data[0];
|
||||
$ids = $request->input('id');
|
||||
switch ($action) {
|
||||
case 'delete':
|
||||
$msg = __(':COUNT items deleted successfully', ['COUNT' => count($ids)]);
|
||||
$this->_MODEL_::destroy($ids);
|
||||
break;
|
||||
case 'status':
|
||||
$this->_MODEL_::whereIn('id', $request->input('id'))->update(['status' => $data[1]]);
|
||||
$msg = __(':COUNT items changed status successfully', ['COUNT' => count($ids)]);
|
||||
break;
|
||||
default:
|
||||
$msg = __('Unknown bulk action : :ACTION', ["ACTION" => $action]);
|
||||
}
|
||||
|
||||
return $this->do_bulk($msg, $action, $ids);
|
||||
}
|
||||
|
||||
public function destroy(Comment $item)
|
||||
{
|
||||
return parent::delete($item);
|
||||
}
|
||||
|
||||
|
||||
public function update(Request $request, Comment $item)
|
||||
{
|
||||
return $this->bringUp($request, $item);
|
||||
}
|
||||
public function status( Comment $item, $status)
|
||||
{
|
||||
$item->status = $status;
|
||||
$item->save();
|
||||
$statuses = [
|
||||
-1 => __('rejected'),
|
||||
0 => __('pending'),
|
||||
1 => __('approved')
|
||||
];
|
||||
return redirect()->back()->with(['message'=> __('Comment :STATUS',['STATUS' => $statuses[$status]]) ]);
|
||||
}
|
||||
|
||||
public function reply(Comment $item){
|
||||
|
||||
return view('admin.comments.comment-reply',compact('item'));
|
||||
}
|
||||
public function replying(Comment $item){
|
||||
|
||||
$c = new Comment();
|
||||
$c->ip = \request()->ip();
|
||||
$c->commentator_type = User::class;
|
||||
$c->commentator_id = auth()->id();
|
||||
$c->commentable_type = $item->commentable_type;
|
||||
$c->commentable_id = $item->commentable_id;
|
||||
$c->parent_id = $item->id;
|
||||
$c->status = 1;
|
||||
$c->body = \request()->input('body');
|
||||
$c->save();
|
||||
|
||||
return redirect()->route('admin.comment.index')->with(['message'=> __('Comment replay')]);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class CommentSaveRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
@extends('admin.templates.panel-form-template')
|
||||
@section('title')
|
||||
@if(isset($item))
|
||||
{{__("Edit comment")}} [{{$item->id}}]
|
||||
@else
|
||||
{{__("Add new comment")}}
|
||||
@endif -
|
||||
@endsection
|
||||
@section('form')
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-3">
|
||||
|
||||
@include('components.err')
|
||||
<div class="item-list mb-3">
|
||||
<h3 class="p-3">
|
||||
<i class="ri-message-3-line"></i>
|
||||
{{__("Tips")}}
|
||||
</h3>
|
||||
<ul>
|
||||
<li>
|
||||
{{__("Recommends")}}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="col-lg-9 ps-xl-1 ps-xxl-1">
|
||||
<div class="general-form ">
|
||||
|
||||
<h1>
|
||||
@if(isset($item))
|
||||
{{__("Edit comment")}} [{{$item->id}}]
|
||||
@else
|
||||
{{__("Add new comment")}}
|
||||
@endif
|
||||
</h1>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
@ -0,0 +1,241 @@
|
||||
@extends('admin.templates.panel-list-template-raw')
|
||||
@section('title')
|
||||
{{__("Comments")}} -
|
||||
@endsection
|
||||
@section('table')
|
||||
<table class="table-list">
|
||||
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
<div
|
||||
data-bs-toggle="tooltip"
|
||||
data-bs-placement="top"
|
||||
data-bs-custom-class="custom-tooltip"
|
||||
data-bs-title="{{__("Check all")}}"
|
||||
class="form-check form-switch mt-1 mx-2">
|
||||
<input class="form-check-input chkall"
|
||||
type="checkbox" role="switch">
|
||||
</div>
|
||||
</th>
|
||||
<th>
|
||||
{{__("Commentator")}}
|
||||
</th>
|
||||
<th>
|
||||
{{__("Comment")}}
|
||||
</th>
|
||||
<th>
|
||||
{{__("Model")}}
|
||||
</th>
|
||||
<th>
|
||||
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@if(count($items) == 0)
|
||||
<tr>
|
||||
<td colspan="100%">
|
||||
{{__("There is nothing to show!")}}
|
||||
</td>
|
||||
</tr>
|
||||
@else
|
||||
@foreach($items as $item)
|
||||
<tr>
|
||||
<td>
|
||||
<input type="checkbox" id="chk-{{$item->id}}" class="chkbox"
|
||||
name="id[{{$item->id}}]" value="{{$item->id}}">
|
||||
<label for="chk-{{$item->id}}">
|
||||
{{$item->id}}
|
||||
</label>
|
||||
</td>
|
||||
<td>
|
||||
@if($item->commentator()['url'] == null)
|
||||
{{$item->commentator()['name']}} [{{$item->commentator()['email']}}]
|
||||
@else
|
||||
<a href="{{$item->commentator()['url']}}">
|
||||
{{$item->commentator()['name']}}
|
||||
</a>
|
||||
@endif
|
||||
<br>
|
||||
{{$item->ip}}
|
||||
</td>
|
||||
<td class="text-start w-50">
|
||||
@if($item->parent != null)
|
||||
<div class="btn btn-dark float-end" data-bs-toggle="tooltip"
|
||||
data-bs-placement="top" data-bs-custom-class="custom-tooltip"
|
||||
data-bs-title="{{$item->parent->id}}.{{$item->parent?->body}}">
|
||||
<i class="ri-message-3-line"></i>
|
||||
</div>
|
||||
@endif
|
||||
{{$item->body}}
|
||||
</td>
|
||||
<td class="text-start">
|
||||
{{$item->commentable->title}}
|
||||
{{$item->commentable->name}}
|
||||
</td>
|
||||
<td style="min-width: 180px">
|
||||
<div class="d-none d-xl-block d-xxl-block">
|
||||
<a href="{{route('admin.comment.destroy',$item->id)}}"
|
||||
class="btn btn-sm btn-danger delete-confirm ms-1" data-bs-toggle="tooltip"
|
||||
data-bs-placement="top" data-bs-custom-class="custom-tooltip"
|
||||
data-bs-title="{{__("Remove")}}">
|
||||
<i class="ri-close-line"></i>
|
||||
</a>
|
||||
@if($item->status != 1)
|
||||
<a href="{{route('admin.comment.status',[$item->id,1])}}"
|
||||
class="btn btn-sm btn-success ms-2" data-bs-toggle="tooltip" data-bs-placement="top"
|
||||
data-bs-custom-class="custom-tooltip"
|
||||
data-bs-title="{{__("Approve")}}">
|
||||
<i class="ri-thumb-up-line"></i>
|
||||
</a>
|
||||
@else
|
||||
<a
|
||||
class="btn btn-sm btn-light ms-2" data-bs-toggle="tooltip" data-bs-placement="top"
|
||||
data-bs-custom-class="custom-tooltip"
|
||||
data-bs-title="{{__("Reply")}}"
|
||||
href="{{route('admin.comment.reply',$item->id)}}">
|
||||
<i class="ri-reply-line"></i>
|
||||
</a>
|
||||
@endif
|
||||
@if($item->status != -1)
|
||||
<a href="{{route('admin.comment.status',[$item->id,-1])}}"
|
||||
class="btn btn-sm btn-warning ms-2" data-bs-toggle="tooltip" data-bs-placement="top"
|
||||
data-bs-custom-class="custom-tooltip"
|
||||
data-bs-title="{{__("Reject")}}">
|
||||
<i class="ri-thumb-down-line"></i>
|
||||
</a>
|
||||
@endif
|
||||
@if($item->status != 0)
|
||||
<a href="{{route('admin.comment.status',[$item->id,0])}}"
|
||||
class="btn btn-sm btn-info ms-2" data-bs-toggle="tooltip" data-bs-placement="top"
|
||||
data-bs-custom-class="custom-tooltip"
|
||||
data-bs-title="{{__("Pending")}}">
|
||||
<i class="ri-hourglass-line"></i>
|
||||
</a>
|
||||
@endif
|
||||
</div>
|
||||
<div class="dropdown d-xl-none d-xxl-none">
|
||||
<a class="btn btn-outline-secondary dropdown-toggle" href="#"
|
||||
role="button"
|
||||
data-bs-toggle="dropdown" aria-expanded="false">
|
||||
</a>
|
||||
<ul class="dropdown-menu">
|
||||
<li>
|
||||
<a class="dropdown-item delete-confirm"
|
||||
href="{{getRoute('destroy',$item->{$item->getRouteKeyName()})}}">
|
||||
<i class="ri-close-line"></i>
|
||||
|
||||
{{__("Remove")}}
|
||||
</a>
|
||||
</li>
|
||||
@if($item->status != 1)
|
||||
<li>
|
||||
<a class="dropdown-item"
|
||||
href="{{route('admin.comment.status',[$item->id,-1])}}">
|
||||
<i class="ri-thumb-up-line"></i>
|
||||
|
||||
{{__("Reject")}}
|
||||
</a>
|
||||
</li>
|
||||
@endif
|
||||
@if($item->status != -1)
|
||||
<li>
|
||||
<a class="dropdown-item"
|
||||
href="{{route('admin.comment.status',[$item->id,-1])}}">
|
||||
<i class="ri-thumb-down-line"></i>
|
||||
|
||||
{{__("Reject")}}
|
||||
</a>
|
||||
</li>
|
||||
@endif
|
||||
@if($item->status != 1)
|
||||
<li>
|
||||
<a class="dropdown-item"
|
||||
href="{{route('admin.comment.status',[$item->id,1])}}">
|
||||
<i class="ri-close-line"></i>
|
||||
|
||||
{{__("Approve")}}
|
||||
</a>
|
||||
</li>
|
||||
@else
|
||||
<li>
|
||||
<a class="dropdown-item"
|
||||
href="{{route('admin.comment.reply',$item->id)}}">
|
||||
<i class="ri-reply-line"></i>
|
||||
|
||||
{{__("Reply")}}
|
||||
</a>
|
||||
</li>
|
||||
@endif
|
||||
@if($item->status != 0)
|
||||
<li>
|
||||
<a class="dropdown-item"
|
||||
href="{{route('admin.comment.status',[$item->id,0])}}">
|
||||
<i class="ri-hourglass-2-line"></i>
|
||||
|
||||
{{__("Pending")}}
|
||||
</a>
|
||||
</li>
|
||||
@endif
|
||||
</ul>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@endforeach
|
||||
@endif
|
||||
|
||||
</tbody>
|
||||
|
||||
|
||||
{{-- pagination and toggle button start --}}
|
||||
<tfoot>
|
||||
<tr>
|
||||
<th colspan="100%">
|
||||
<div class="row">
|
||||
<div class="col-md-3 text-start">
|
||||
<div
|
||||
id="toggle-select"
|
||||
class="btn btn-outline-light mx-2"
|
||||
data-bs-toggle="tooltip"
|
||||
data-bs-placement="top"
|
||||
data-bs-custom-class="custom-tooltip"
|
||||
data-bs-title="{{__("Toggle selection")}}">
|
||||
<i class="ri-toggle-line"></i>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
{{$items->withQueryString()->links()}}
|
||||
</div>
|
||||
<div class="col-md-3 text-center">
|
||||
</div>
|
||||
</div>
|
||||
</th>
|
||||
</tr>
|
||||
</tfoot>
|
||||
{{-- pagination and toggle button end --}}
|
||||
</table>
|
||||
@endsection
|
||||
|
||||
@section('filter')
|
||||
<h2>
|
||||
<i class="ri-info-i"></i>
|
||||
{{__("Status")}}:
|
||||
</h2>
|
||||
<searchable-multi-select
|
||||
:items='@json(commentStatuses())'
|
||||
title-field="name"
|
||||
value-field="id"
|
||||
xname="filter[status]"
|
||||
:xvalue='{{request()->input('filter.status','[]')}}'
|
||||
:close-on-Select="true"></searchable-multi-select>
|
||||
@endsection
|
||||
|
||||
@section('bulk')
|
||||
<option value="status.-1"> {{__('Reject')}} </option>
|
||||
<option value="status.0"> {{__('Pending')}} </option>
|
||||
<option value="status.1"> {{__('Approve')}} </option>
|
||||
@endsection
|
||||
@section('side-raw')
|
||||
@endsection
|
@ -0,0 +1,35 @@
|
||||
@extends('layouts.app')
|
||||
@section('title')
|
||||
{{__("Reply comment")}} -
|
||||
@endsection
|
||||
@section('content')
|
||||
<form action="{{route('admin.comment.replying',$item->id)}}" method="post">
|
||||
@csrf
|
||||
|
||||
<div>
|
||||
<div class="general-form ">
|
||||
|
||||
<h4 class="p-3">
|
||||
<i class="ri-message-2-line"></i>
|
||||
{{$item->body}}
|
||||
</h4>
|
||||
|
||||
<input type="hidden" id="{{$item->id}}" name="id">
|
||||
<div class="row">
|
||||
<div class="col-md-12 mt-3">
|
||||
<div class="form-group">
|
||||
<label for="body" >
|
||||
{{__('Message replay')}}
|
||||
</label>
|
||||
<textarea name="body" id="body" class="form-control @error('body') is-invalid @enderror" placeholder="{{__('Message')}}" >{{old('body')}}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12">
|
||||
<label> </label>
|
||||
<input type="submit" class="btn btn-primary mt-2" value="{{__('Save')}}" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
@endsection
|
Loading…
Reference in New Issue