diff --git a/app/CommentReply.php b/app/CommentReply.php new file mode 100644 index 0000000..f22b48f --- /dev/null +++ b/app/CommentReply.php @@ -0,0 +1,15 @@ +belongsTo('App\Comment'); + } + public function user(){ + return $this->belongsTo('App\User'); + } +} diff --git a/app/Http/Controllers/Admin/CommentReplyController.php b/app/Http/Controllers/Admin/CommentReplyController.php new file mode 100644 index 0000000..4ea44d4 --- /dev/null +++ b/app/Http/Controllers/Admin/CommentReplyController.php @@ -0,0 +1,24 @@ +delete(); + Toastr::success('Comment successfully deleted :)'); + return redirect()->back(); + } +} diff --git a/app/Http/Controllers/CommentReplyController.php b/app/Http/Controllers/CommentReplyController.php new file mode 100644 index 0000000..c0d56b7 --- /dev/null +++ b/app/Http/Controllers/CommentReplyController.php @@ -0,0 +1,25 @@ +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(); + } +} diff --git a/app/Http/Controllers/User/CommentReplyController.php b/app/Http/Controllers/User/CommentReplyController.php new file mode 100644 index 0000000..08e87e3 --- /dev/null +++ b/app/Http/Controllers/User/CommentReplyController.php @@ -0,0 +1,30 @@ +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(); + } + } +} diff --git a/database/migrations/2020_10_13_064245_create_comment_replies_table.php b/database/migrations/2020_10_13_064245_create_comment_replies_table.php new file mode 100644 index 0000000..3128f92 --- /dev/null +++ b/database/migrations/2020_10_13_064245_create_comment_replies_table.php @@ -0,0 +1,34 @@ +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'); + } +} diff --git a/resources/views/admin/reply-comments/index.blade.php b/resources/views/admin/reply-comments/index.blade.php new file mode 100644 index 0000000..46112d0 --- /dev/null +++ b/resources/views/admin/reply-comments/index.blade.php @@ -0,0 +1,168 @@ +@extends('layouts.backend.app') +@push('header') + + + +@endpush +@section('content') +
+ + +
+
+
+
+ @if ($errors->any()) + + @foreach ($errors->all() as $error) + + @endforeach + + @endif + +
+
+
+
+ Replied Comments Table +
+
+ + + + + + + + + + + + + + @foreach ($reply_comments as $key => $reply_comment) + + + + + + + + + + @endforeach + + +
#Replied CommentTo CommentRelied UserPostCreated_AtAction
{{$key+1}}{{$reply_comment->message}}{{$reply_comment->comment->comment}}{{$reply_comment->user->name}}{{$reply_comment->comment->post->title}}{{$reply_comment->created_at->diffForHumans()}} + +
+ +
+
+
+
+
+ +
+ @foreach ($reply_comments as $reply_comment) + + @endforeach + + + +
+ + + +@endsection + +@push('footer') + + + + + + + + + + + + + + + {!! Toastr::message() !!} +@endpush diff --git a/resources/views/user/reply-comments/index.blade.php b/resources/views/user/reply-comments/index.blade.php new file mode 100644 index 0000000..f734e33 --- /dev/null +++ b/resources/views/user/reply-comments/index.blade.php @@ -0,0 +1,166 @@ +@extends('layouts.backend.app') +@push('header') + + + +@endpush +@section('content') +
+ + +
+
+
+
+ @if ($errors->any()) + + @foreach ($errors->all() as $error) + + @endforeach + + @endif + +
+
+
+
+ Replied Comments Table +
+
+ + + + + + + + + + + + + @foreach ($reply_comments as $key => $reply_comment) + + + + + + + + + @endforeach + + +
#Replied CommentTo CommentPostCreated_AtAction
{{$key+1}}{{$reply_comment->message}}{{$reply_comment->comment->comment}}{{$reply_comment->comment->post->title}}{{$reply_comment->created_at->diffForHumans()}} + +
+ +
+
+
+
+
+ +
+ @foreach ($reply_comments as $reply_comment) + + @endforeach + + + +
+ + + +@endsection + +@push('footer') + + + + + + + + + + + + + + + {!! Toastr::message() !!} +@endpush