47 lines
1.3 KiB
PHP
47 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Notifications;
|
|
|
|
use Livewire\Component;
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
|
|
class NotificationList extends Component
|
|
{
|
|
|
|
public $notifications = [];
|
|
public $updating = false;
|
|
|
|
public function mount()
|
|
{
|
|
// Placeholder role check (replace with middleware or actual auth logic)
|
|
// if (auth()->user()->role != 1) {
|
|
// $this->alert('error', 'Unauthorized access.');
|
|
// return redirect('/'); // Adjust redirect as needed
|
|
// }
|
|
$this->fetchNotifications();
|
|
}
|
|
|
|
public function fetchNotifications()
|
|
{
|
|
try {
|
|
$this->updating = true;
|
|
$response = Http::get('https://api.example.com/notification');
|
|
if ($response->successful()) {
|
|
$this->notifications = $response->json()['data'] ?? [];
|
|
} else {
|
|
$this->alert('error', 'Failed to fetch notifications.');
|
|
}
|
|
} catch (\Exception $e) {
|
|
$this->alert('error', 'An error occurred: ' . $e->getMessage());
|
|
} finally {
|
|
$this->updating = false;
|
|
}
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.notifications.notification-list')->layout('layouts.app', ['title' => 'Notifications']);
|
|
}
|
|
}
|