50 lines
1.3 KiB
PHP
50 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\MyProfile;
|
|
|
|
use Livewire\Component;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Jantinnerezo\LivewireAlert\LivewireAlert;
|
|
|
|
class MyProfileView extends Component
|
|
{
|
|
use LivewireAlert;
|
|
|
|
public $userInfo = null;
|
|
|
|
public function mount()
|
|
{
|
|
$this->fetchProfile();
|
|
}
|
|
|
|
public function fetchProfile()
|
|
{
|
|
try {
|
|
$response = Http::post('https://api.example.com/adminProfile');
|
|
if ($response->successful()) {
|
|
$this->userInfo = $response->json()['data'] ?? null;
|
|
} else {
|
|
$this->alert('error', 'Failed to fetch profile data.', ['duration' => 20000]);
|
|
$this->userInfo = null;
|
|
}
|
|
} catch (\Exception $e) {
|
|
$this->alert('error', 'An error occurred: ' . $e->getMessage(), ['duration' => 20000]);
|
|
$this->userInfo = null;
|
|
}
|
|
}
|
|
|
|
public function getRoleLabel($role)
|
|
{
|
|
if ($role == '1') {
|
|
return 'System Admin';
|
|
} elseif ($role == '3') {
|
|
return 'Super Admin';
|
|
}
|
|
return 'Marketing Personnel';
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.my-profile.my-profile-view')->layout('layouts.app', ['title' => 'My Profile']);
|
|
}
|
|
} |