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

name : FaqController.php
<?php

namespace App\Http\Controllers\admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Str;
use Illuminate\Support\Response;
use App\Models\Faq;

class FaqController extends Controller
{
    //
    public function __construct()
    {
        $this->middleware('auth');
        $this->middleware('isAdmin');
    }

    public function index()
    {
        $data['faqs'] = Faq::all();
        return view('admin/faqs',$data);
    }

    public function add_faq()
    {
        return view("admin/add_faq");
    }

    public function insert_faq(Request $req)
    {
        if ($req->faqStatus == true) 
        {
            $status = 1;
        }
        else
        {
            $status = 0;
        }

        $validation = Validator::make($req->all(),[
            'faqQuestion' => 'required',
            'faqAnswer' => 'required',
        ],[
            'faqQuestion.required' => 'Faq Question Is Required',
            'faqAnswer.required' => 'Faq Answer Is Required',
        ]);

        if(!$validation->passes())
        {
            return response()->json(['error'=>$validation->errors()]);
        }
        else
        {
            $AddFaq = new Faq;
            $AddFaq->faq_question = $req->faqQuestion;
            $AddFaq->faq_answer = $req->faqAnswer;
            $AddFaq->faq_status = $status;
        }

        $AddFaq->save();
        return response()->json(['success'=>'Faq Add Successfully']);
    }

    public function update_faq(Request $req)
    {
        if ($req->FaqStatus == true) 
        {
            $status = 1;
        }
        else
        {
            $status = 0;
        }

        $validation = Validator::make($req->all(),[
            'FaqQuestion' => 'required',
            'FaqAnswer' => 'required',
        ],[
            'FaqQuestion.required' => 'Faq Question Is Required',
            'FaqAnswer.required' => 'Faq Answer Is Required',
        ]);

        if(!$validation->passes())
        {
            return response()->json(['error'=>$validation->errors()]);
        }
        else
        {
            $id = $req->FaqId;
            $UpdateFaq = Faq::find($id);
            $UpdateFaq->faq_question = $req->FaqQuestion;
            $UpdateFaq->faq_answer = $req->FaqAnswer;
            $UpdateFaq->faq_status = $status;
        }

        $UpdateFaq->save();
        return response()->json(['success'=>'Faq Updated Successfully']);
    }

    public function delete_faq(Request $req)
    {
        $id = $req->id;
        $DeleteFaq = Faq::find($id);
        $DeleteFaq->delete();
    }
}
© 2025 GrazzMean-Shell