GOOD SHELL MAS BOY
Server: Apache/2.4.52 (Ubuntu)
System: Linux vmi1836763.contaboserver.net 5.15.0-130-generic #140-Ubuntu SMP Wed Dec 18 17:59:53 UTC 2024 x86_64
User: www-data (33)
PHP: 8.4.10
Disabled: NONE
Upload Files
File: /var/www/html/app/Livewire/Faq/Add.php
<?php

namespace App\Livewire\Faq;

use Livewire\Component;
use App\Services\ApiEndpoints;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Session;

class Add extends Component
{
    public $gig_id;
    public $question;
    public $answer;
    public $user_id;

    protected $rules = [
        'gig_id' => 'required|exists:gigs,id',
        'question' => 'required|unique:faqs',
        'answer' => 'required|string|max:255',
    ];

    public function addGigFaq()
    {
        // Validate input data
        try {
            $this->validate();
            // Store the FAQ data
            $body = [
                'gig_id' => $this->gig_id,
                'question' => $this->question,
                'answer' => $this->answer,
            ];

            $apiEndpoints = new ApiEndpoints();
            $headers = $apiEndpoints->header();
            $response = Http::withHeaders($headers)
                ->withBody(json_encode($body), 'application/json')
                ->post(ApiEndpoints::addFaq());
            if ($response->successful()) {
                Session::flash('success', 'Successfully added');
                return redirect()->to('/dashboard-faqs');
            } else {
                Session::flash('success', $response->json()['message']);
                return redirect()->to('/dashboard-faq');
            }
        } catch (\Throwable $th) {
            $this->addError('answer', $th->getMessage());
        }
    }
    public function render()
    {
        $seller = session()->get('user');
        $this->user_id = $seller['id'];

        $gigs = DB::table('gigs')->where('user_id', $this->user_id)->get();
        return view('livewire.faq.add', compact('gigs'));
    }
}