-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a04d1cc
commit bf7c5ff
Showing
7 changed files
with
462 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace App; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class CommentReply extends Model | ||
{ | ||
public function comment(){ | ||
return $this->belongsTo('App\Comment'); | ||
} | ||
public function user(){ | ||
return $this->belongsTo('App\User'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Admin; | ||
|
||
use App\CommentReply; | ||
use App\Http\Controllers\Controller; | ||
use Brian2694\Toastr\Facades\Toastr; | ||
use Illuminate\Http\Request; | ||
|
||
class CommentReplyController extends Controller | ||
{ | ||
public function index() | ||
{ | ||
$reply_comments = CommentReply::all(); | ||
return view('admin.reply-comments.index', compact('reply_comments')); | ||
} | ||
public function destroy($id) | ||
{ | ||
$reply_comment = CommentReply::findOrFail($id); | ||
$reply_comment->delete(); | ||
Toastr::success('Comment successfully deleted :)'); | ||
return redirect()->back(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\CommentReply; | ||
use Brian2694\Toastr\Facades\Toastr; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
|
||
class CommentReplyController extends Controller | ||
{ | ||
public function store(Request $request, $comment) | ||
{ | ||
$this->validate($request, ['message' => 'required|max:1000']); | ||
$commentReply = new CommentReply(); | ||
$commentReply->comment_id = $comment; | ||
$commentReply->user_id = Auth::id(); | ||
$commentReply->message = $request->message; | ||
$commentReply->save(); | ||
|
||
// Success message | ||
Toastr::success('success', 'The comment replied successfully ;)'); | ||
return redirect()->back(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\User; | ||
|
||
use App\CommentReply; | ||
use App\Http\Controllers\Controller; | ||
use Brian2694\Toastr\Facades\Toastr; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
|
||
class CommentReplyController extends Controller | ||
{ | ||
public function index() | ||
{ | ||
$reply_comments = CommentReply::where('user_id', Auth::id())->get(); | ||
return view('user.reply-comments.index', compact('reply_comments')); | ||
} | ||
public function destroy($id) | ||
{ | ||
$reply_comment = CommentReply::findOrFail($id); | ||
if ($reply_comment->user_id == Auth::id()) { | ||
$reply_comment->delete(); | ||
Toastr::success('Comment successfully deleted :)'); | ||
return redirect()->back(); | ||
} else { | ||
Toastr::error('You can not delete this comment :('); | ||
return redirect()->back(); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
database/migrations/2020_10_13_064245_create_comment_replies_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class CreateCommentRepliesTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('comment_replies', function (Blueprint $table) { | ||
$table->id(); | ||
$table->unsignedBigInteger('comment_id'); | ||
$table->unsignedBigInteger('user_id'); | ||
$table->text('message'); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists('comment_replies'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
@extends('layouts.backend.app') | ||
@push('header') | ||
<link rel="stylesheet" href="{{asset('backend/vendors/datatables.net-bs4/css/dataTables.bootstrap4.min.css')}}" /> | ||
<link rel="stylesheet" href="{{asset('backend/vendors/datatables.net-buttons-bs4/css/buttons.bootstrap4.min.css')}}" /> | ||
<link rel="stylesheet" href="http://cdn.bootcss.com/toastr.js/latest/css/toastr.min.css"> | ||
@endpush | ||
@section('content') | ||
<div id="right-panel" class="right-panel"> | ||
<div class="breadcrumbs"> | ||
<div class="col-sm-4"> | ||
<div class="page-header float-left"> | ||
<div class="page-title"> | ||
<h1>Replied Comments</h1> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="col-sm-8"> | ||
<div class="page-header float-right"> | ||
<div class="page-title"> | ||
<ol class="breadcrumb text-right"> | ||
<li><a href="#">Dashboard</a></li> | ||
<li> | ||
<a href="#" class="active">Replied Comments</a> | ||
</li> | ||
</ol> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="content mt-3"> | ||
<div class="animated fadeIn"> | ||
<div class="row"> | ||
<div class="col-md-12"> | ||
@if ($errors->any()) | ||
|
||
@foreach ($errors->all() as $error) | ||
<div class="alert alert-danger alert-dismissible fade show" role="alert"> | ||
<span class="badge badge-pill badge-danger">Erorr</span> {{$error}} | ||
<button type="button" class="close" data-dismiss="alert" aria-label="Close"> | ||
<span aria-hidden="true">×</span> | ||
</button> | ||
</div> | ||
@endforeach | ||
|
||
@endif | ||
|
||
</div> | ||
<div class="col-md-12"> | ||
<div class="card"> | ||
<div class="card-header"> | ||
<strong class="card-title">Replied Comments Table</strong> | ||
</div> | ||
<div class="card-body"> | ||
<table id="bootstrap-data-table-export" class="table table-striped table-bordered"> | ||
<thead> | ||
<tr> | ||
<th>#</th> | ||
<th>Replied Comment</th> | ||
<th>To Comment</th> | ||
<th>Relied User</th> | ||
<th>Post</th> | ||
<th>Created_At</th> | ||
<th>Action</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@foreach ($reply_comments as $key => $reply_comment) | ||
<tr> | ||
<td>{{$key+1}}</td> | ||
<td>{{$reply_comment->message}}</td> | ||
<td>{{$reply_comment->comment->comment}}</td> | ||
<td>{{$reply_comment->user->name}}</td> | ||
<td><a href="{{route('post',$reply_comment->comment->post->slug)}}">{{$reply_comment->comment->post->title}}</a></td> | ||
<td>{{$reply_comment->created_at->diffForHumans()}}</td> | ||
<td> | ||
<button type="button" class="btn btn-danger mb-1" data-toggle="modal" | ||
data-target="#deleteModal-{{$reply_comment->id}}"> | ||
<i class="fa fa-trash-o"></i> | ||
</button> | ||
</td> | ||
</tr> | ||
@endforeach | ||
|
||
</tbody> | ||
</table> | ||
|
||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<!-- .animated --> | ||
<div class="animated"> | ||
@foreach ($reply_comments as $reply_comment) | ||
<div class="modal fade" id="deleteModal-{{$reply_comment->id}}" tabindex="-1" role="dialog" aria-labelledby="staticModalLabel" | ||
data-backdrop="static" aria-hidden="true" style="display: none;"> | ||
<div class="modal-dialog modal-sm" role="document"> | ||
<div class="modal-content"> | ||
<div class="modal-header"> | ||
<h5 class="modal-title" id="staticModalLabel">Delete Comment</h5> | ||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"> | ||
<span aria-hidden="true">×</span> | ||
</button> | ||
</div> | ||
<div class="modal-body"> | ||
<p> | ||
The Comment will be deleted !! | ||
</p> | ||
</div> | ||
<div class="modal-footer"> | ||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button> | ||
<button type="button" class="btn btn-danger" onclick="event.preventDefault(); | ||
document.getElementById('deletecomment-{{$reply_comment->id}}').submit();">Confirm</button> | ||
<form action="{{route('admin.reply-comment.destroy', $reply_comment->id)}}" style="display: none" id="deletecomment-{{$reply_comment->id}}" method="POST"> | ||
@csrf | ||
@method('DELETE') | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
@endforeach | ||
|
||
|
||
<!-- .content --> | ||
</div> | ||
|
||
|
||
<!-- .content --> | ||
@endsection | ||
|
||
@push('footer') | ||
|
||
<script src="{{asset('backend/vendors/datatables.net/js/jquery.dataTables.min.js')}}"></script> | ||
<script src="{{asset('backend/vendors/datatables.net-bs4/js/dataTables.bootstrap4.min.js')}}"></script> | ||
<script src="{{asset('backend/vendors/datatables.net-buttons/js/dataTables.buttons.min.js')}}"></script> | ||
<script src="{{asset('backend/vendors/datatables.net-buttons-bs4/js/buttons.bootstrap4.min.js')}}"></script> | ||
<script src="{{asset('backend/vendors/jszip/dist/jszip.min.js')}}"></script> | ||
<script src="{{asset('backend/vendors/pdfmake/build/pdfmake.min.js')}}"></script> | ||
<script src="{{asset('backend/vendors/pdfmake/build/vfs_fonts.js')}}"></script> | ||
<script src="{{asset('backend/vendors/datatables.net-buttons/js/buttons.html5.min.js')}}"></script> | ||
<script src="{{asset('backend/vendors/datatables.net-buttons/js/buttons.print.min.js')}}"></script> | ||
<script src="{{asset('backend/vendors/datatables.net-buttons/js/buttons.colVis.min.js')}}"></script> | ||
<script src="{{asset('backend/assets/js/init-scripts/data-table/datatables-init.js')}}"> | ||
<script> | ||
$(document).ready(function () { | ||
(function ($) { | ||
$('#filter').keyup(function () { | ||
var rex = new RegExp($(this).val(), 'i'); | ||
$('.searchable tr').hide(); | ||
$('.searchable tr').filter(function () { | ||
return rex.test($(this).text()); | ||
}).show(); | ||
}) | ||
}(jQuery)); | ||
}); | ||
</script> | ||
<script src="http://cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script> | ||
<script src="http://cdn.bootcss.com/toastr.js/latest/js/toastr.min.js"></script> | ||
{!! Toastr::message() !!} | ||
@endpush |
Oops, something went wrong.