45 lines
1.3 KiB
PHP
45 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\AboutUs\TermAndPrivacy;
|
|
|
|
use Livewire\Component;
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
class TermAndPrivacyView extends Component
|
|
{
|
|
public $term;
|
|
|
|
public function mount($id)
|
|
{
|
|
try {
|
|
$this->term = $this->fetchFromApi("https://api.example.com/TermsAndPrivacy/{$id}");
|
|
} catch (\Exception $e) {
|
|
session()->flash('error', 'Failed to load term details: ' . $e->getMessage());
|
|
return redirect()->route('term-privacy.list');
|
|
}
|
|
}
|
|
|
|
private function fetchFromApi($url)
|
|
{
|
|
$response = Http::get($url);
|
|
return $response->json()['data'] ?? null;
|
|
}
|
|
|
|
public function delete($uuid)
|
|
{
|
|
try {
|
|
$response = Http::delete("https://api.example.com/TermsAndPrivacy/{$uuid}");
|
|
if ($response->successful()) {
|
|
session()->flash('success', 'Record was successfully deleted.');
|
|
return redirect()->route('term-privacy.list');
|
|
}
|
|
} catch (\Exception $e) {
|
|
session()->flash('error', 'Failed to delete record: ' . $e->getMessage());
|
|
}
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.about-us.term-and-privacy.term-and-privacy-view', ['term' => $this->term]);
|
|
}
|
|
} |