added notifications
This commit is contained in:
@@ -14,6 +14,7 @@ use App\Models\FormVehicleRunningCost;
|
||||
use App\Models\FormMeetingSeminar;
|
||||
use App\Models\FormOthers;
|
||||
use App\Models\UserHasCabang;
|
||||
use App\Models\Notifications;
|
||||
|
||||
|
||||
class DashboardController extends Controller
|
||||
@@ -99,4 +100,43 @@ class DashboardController extends Controller
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function notifications()
|
||||
{
|
||||
$this->checkAuthorization(auth()->user(), ['notification.view']);
|
||||
$role = auth()->user()->getRoleNames()[0];
|
||||
|
||||
// Mulai dengan query dasar
|
||||
$notifications = Notifications::orderBy('created_at', 'desc')
|
||||
->where('receiver_id', auth()->user()->id)
|
||||
->where('is_read', 0);
|
||||
|
||||
// Tambahkan filter berdasarkan role
|
||||
if ($role == 'Admin Region') {
|
||||
$notifications->where('type', 'new_expense');
|
||||
} elseif ($role == 'Marketing Operational Manager Region') {
|
||||
$notifications->where('type', 'approve2_expense');
|
||||
} elseif ($role == 'Area Manager Cabang' || $role == 'Marketing Information System') {
|
||||
$notifications->where('type', 'approve_expense');
|
||||
} elseif ($role == 'Head of Sales Marketing') {
|
||||
$notifications->where('type', 'approve2_expense');
|
||||
} else {
|
||||
// Jika tidak ada role yang sesuai, kembalikan koleksi kosong
|
||||
return response()->json([]);
|
||||
}
|
||||
|
||||
// Ambil data dan kembalikan sebagai JSON
|
||||
return response()->json($notifications->limit(6)->get());
|
||||
}
|
||||
|
||||
public function mark_read()
|
||||
{
|
||||
$this->checkAuthorization(auth()->user(), ['notification.delete']);
|
||||
$receiver_id = auth()->user()->id;
|
||||
|
||||
Notifications::where('receiver_id', $receiver_id)->update(['is_read' => 1]);
|
||||
|
||||
session()->flash('success', 'Notifications marked as read.');
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user