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.144.76.238
User: allssztx (535) | Group: allssztx (533)
Safe Mode: OFF
Disable Function:
NONE

name : ProductCommentController.php
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;
use Illuminate\Http\Response;
use App\Models\Product;
use App\Models\ProductComment;

class ProductCommentController extends Controller
{
    //
    public function insert(Request $req)
    {
        $id = $req->proId;
        $product = Product::find($id);
        if(!$product)
        {
            return response()->json(['proerror'=>'Product Not Found!']);
        }

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

        if(!$validation->passes())
        {
            return response()->json(['error'=>$validation->errors()]);
        }
        else
        {
            $AddComment = new ProductComment;
            $AddComment->product_id = $id;
            $AddComment->user_name = $req->userName;
            $AddComment->user_email = $req->userEmail;
            $AddComment->comment = $req->Comment;
            $AddComment->rating = $req->star_rating;
            $AddComment->save();
            return response()->json(['success'=>'Comment Add Successfully']);
        }
    }
}
© 2025 GrazzMean-Shell