Uname: Linux business55.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64
Software: LiteSpeed
PHP version: 8.1.31 [ PHP INFO ] PHP os: Linux
Server Ip: 162.213.251.212
Your Ip: 3.133.135.89
User: allssztx (535) | Group: allssztx (533)
Safe Mode: OFF
Disable Function:
NONE

name : CommentController.php
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Response;
use Illuminate\Support\Str;
use App\Models\Comment;
use App\Models\CommentReplay;
use App\Models\Post;
use Auth;

class CommentController extends Controller
{
    //
    public function insert_comment(Request $req)
    {
        if(auth()->check())
        {
            $id = $req->postId;
            $post = Post::find($id);
            if(!$post)
            {
                return response()->json(['posterror'=>'Post Not Found!']);
            }

            $validation = Validator::make($req->all(),[
                'Comment' => 'required|max:3000',
            ],[
                'Comment.required' => 'Please Enter Comment Text',
                'Comment.max' => 'Comment Max Length Is 3000',
            ]);

            if(!$validation->passes())
            {
                return response()->json(['error'=>$validation->errors()]);
            }
            else
            {
                $AddComment = new Comment;
                $AddComment->post_id = $id;
                $AddComment->user_id = Auth::user()->id;
                $AddComment->comment = $req->Comment;
                $AddComment->save();
                return response()->json(['success'=>'Comment Add Successfully']);
            }
        }
        else
        {
            return response()->json(['loginerror'=>'Please Login First']);
        }
        
    }

    public function reply_comment(Request $req)
    {
        if(auth()->check())
        {
            $id = $req->commentId;
            $comment = Comment::find($id);
            if(!$comment)
            {
                return response()->json(['commenterror'=>'Comment Not Found!']);
            }

            $validation = Validator::make($req->all(),[
                'reply' => 'required|max:3000',
            ],[
                'reply.required' => 'Please Enter Comment Text',
                'reply.max' => 'Comment Max Length Is 3000',
            ]);

            if(!$validation->passes())
            {
                return response()->json(['error'=>$validation->errors()]);
            }
            else
            {
                $AddReply = new CommentReplay;
                $AddReply->comment_id = $req->commentId;
                $AddReply->user_id = Auth::user()->id;
                $AddReply->comment = $req->reply;
                $AddReply->save();
                return response()->json(['success'=>'Replay Add Successfully']);
            }
        }
        else
        {
            return response()->json(['loginerror'=>'Please Login First']);
        }
    }
}
© 2025 GrazzMean-Shell