-
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
500965e
commit 41f601a
Showing
13 changed files
with
678 additions
and
82 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,17 @@ | ||
<?php | ||
|
||
namespace App; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Comment extends Model | ||
{ | ||
public function post() | ||
{ | ||
return $this->belongsTo('App\Post'); | ||
} | ||
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\Comment; | ||
use App\Http\Controllers\Controller; | ||
use Brian2694\Toastr\Facades\Toastr; | ||
use Illuminate\Http\Request; | ||
|
||
class CommentController extends Controller | ||
{ | ||
public function index() | ||
{ | ||
$comments = Comment::all(); | ||
return view('admin.comments.index', compact('comments')); | ||
} | ||
public function destroy($id) | ||
{ | ||
$comment = Comment::findOrFail($id); | ||
$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\Comment; | ||
use Brian2694\Toastr\Facades\Toastr; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
|
||
class CommentController extends Controller | ||
{ | ||
public function store(Request $request, $post) | ||
{ | ||
$this->validate($request, ['comment' => 'required|max:1000']); | ||
$comment = new Comment(); | ||
$comment->post_id = $post; | ||
$comment->user_id = Auth::id(); | ||
$comment->comment = $request->comment; | ||
$comment->save(); | ||
|
||
// Success message | ||
Toastr::success('success', 'The comment created 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\Comment; | ||
use App\Http\Controllers\Controller; | ||
use Brian2694\Toastr\Facades\Toastr; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
|
||
class CommentController extends Controller | ||
{ | ||
public function index() | ||
{ | ||
$comments = Comment::where('user_id', Auth::id())->latest()->get(); | ||
return view('user.comments.index', compact('comments')); | ||
} | ||
public function destroy($id) | ||
{ | ||
$comment = Comment::findOrFail($id); | ||
if ($comment->user_id == Auth::id()) { | ||
$comment->delete(); | ||
Toastr::success('Comment successfully deleted :)'); | ||
return redirect()->back(); | ||
} else { | ||
Toastr::error('You can not delete this comment :('); | ||
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
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
34 changes: 34 additions & 0 deletions
34
database/migrations/2020_10_07_072827_create_comments_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 CreateCommentsTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('comments', function (Blueprint $table) { | ||
$table->id(); | ||
$table->unsignedBigInteger('post_id'); | ||
$table->unsignedBigInteger('user_id'); | ||
$table->text('comment'); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists('comments'); | ||
} | ||
} |
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,166 @@ | ||
@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>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">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">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>Comment</th> | ||
<th>User</th> | ||
<th>Post</th> | ||
<th>Created_At</th> | ||
<th>Action</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@foreach ($comments as $key => $comment) | ||
<tr> | ||
<td>{{$key+1}}</td> | ||
<td>{{$comment->comment}}</td> | ||
<td>{{$comment->user->name}}</td> | ||
<td><a href="{{route('post',$comment->post->slug)}}">{{$comment->post->title}}</a></td> | ||
<td>{{$comment->created_at->diffForHumans()}}</td> | ||
<td> | ||
<button type="button" class="btn btn-danger mb-1" data-toggle="modal" | ||
data-target="#deleteModal-{{$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 ($comments as $comment) | ||
<div class="modal fade" id="deleteModal-{{$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-{{$comment->id}}').submit();">Confirm</button> | ||
<form action="{{route('admin.comment.destroy', $comment->id)}}" style="display: none" id="deletecomment-{{$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 |
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
Oops, something went wrong.