unioil-cms-fe/app/Livewire/Buttons/ViewTermsAndPrivacy.php

45 lines
1.2 KiB
PHP

<?php
namespace App\Livewire\Buttons;
use Livewire\Component;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Session as SessionFacade;
class ViewTermsAndPrivacy extends Component
{
public $uuid;
public $title,
$details,
$type;
public function mount($uuid)
{
$this->uuid = $uuid;
$token = Session::get('user')['access_token'] ?? null;
if (!$token) {
$this->addError('users', 'No access token found.');
return;
}
$response = Http::withToken($token)->get(config('services.backend_api.url') . "/api/cms/TermsAndPrivacy/{$uuid}");
if ($response->successful()) {
$termsAndPrivacy = $response->json('data');
$this->type = $termsAndPrivacy['type'] ?? '';
$this->title = $termsAndPrivacy['title'] ?? '';
$this->details = $termsAndPrivacy['details'] ?? '';
} else {
$this->addError('terms and privacy', 'Failed to fetch terms and privacy data.');
}
}
public function render()
{
return view('livewire.buttons.view-terms-and-privacy');
}
}