Skip to content

Commit 2f25676

Browse files
committed
Add page to show all notifications
1 parent 78426ec commit 2f25676

File tree

6 files changed

+71
-16
lines changed

6 files changed

+71
-16
lines changed

app/Http/Controllers/NotificationController.php

+20
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
namespace App\Http\Controllers;
44

5+
use App\Notification;
6+
use Carbon\Carbon;
7+
58
class NotificationController extends Controller
69
{
710
/**
@@ -38,4 +41,21 @@ public function markRead($notificationId)
3841
'success' => false
3942
]);
4043
}
44+
45+
/**
46+
* View all notifications
47+
*
48+
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
49+
*/
50+
public function viewAll()
51+
{
52+
$notifications = auth()->user()->notifications->groupBy(function ($notification, $key) {
53+
return $notification->created_at->format('y-m-d');
54+
});
55+
56+
// Mark as read if unread
57+
$notifications->each->markAsRead();
58+
59+
return view('notification.all', compact('notifications'));
60+
}
4161
}

app/Notification.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,13 @@
66

77
class Notification extends Model
88
{
9-
//
9+
/**
10+
* The attributes that should be cast to native types.
11+
*
12+
* @var array
13+
*/
14+
protected $casts = [
15+
'data' => 'array',
16+
'read_at' => 'datetime',
17+
];
1018
}

resources/assets/js/components/Notifications.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
:key="notification.id"
1313
:notification="notification"/>
1414

15-
<a class="dropdown-item notification__all text-center" href="#"> View all Notifications </a>
15+
<a class="dropdown-item notification__all text-center" href="/all-notifications"> View all Notifications </a>
1616
</div>
1717
</div>
1818
</template>

resources/views/notification.blade.php

+12-14
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
@if($notification->type === 'App\Notifications\HolidayAdded')
2-
<a class="dropdown-item" href="{{ url('holidays', $notification->data['id']) }}">
3-
<div class="notification__icon-wrapper">
4-
<div class="notification__icon">
5-
<i class="far fa-snowflake"></i>
6-
</div>
7-
</div>
2+
<a href="{{ url('holidays', $notification->data['id']) }}">
83
<div class="notification__content">
94
<span class="notification__category">Holiday Alert</span>
105
<p>We have Holiday for {{ array_get($notification->data, 'title') }} from
@@ -13,15 +8,18 @@
138
</p>
149
</div>
1510
</a>
16-
@endif
17-
18-
@if($notification->type === 'App\Notifications\LeaveApproval')
19-
<a class="dropdown-item" href="{{ url('leaves', $notification->data['id']) }}">
20-
<div class="notification__icon-wrapper">
21-
<div class="notification__icon">
22-
<i class="far fa-snowflake"></i>
23-
</div>
11+
@elseif($notification->type === 'App\Notifications\LeaveRequested')
12+
<a href="{{ url('leaves', $notification->data['id']) }}">
13+
<div class="notification__content">
14+
<span class="notification__category">Leave Request</span>
15+
<p>Your have requestd for leave for {{ array_get($notification->data, 'subject') }} from
16+
<span class="text-success text-semibold">{{ array_get($notification->data, 'start_date') }}</span> To
17+
<span class="text-success text-semibold">{{ array_get($notification->data, 'end_date') }}</span>
18+
</p>
2419
</div>
20+
</a>
21+
@elseif($notification->type === 'App\Notifications\LeaveApproval')
22+
<a href="{{ url('leaves', $notification->data['id']) }}">
2523
<div class="notification__content">
2624
<span class="notification__category">Leave Approval Alert</span>
2725
<p>Your Leave request for {{ array_get($notification->data, 'subject') }} from
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
@extends('layouts.app', [
2+
'pageTitle' => 'All Notifications'
3+
])
4+
5+
@section('content')
6+
<div class="container pg-dashboard">
7+
@forelse($notifications as $key => $values)
8+
<div class="row mb-3">
9+
<h6 class="text">{{ $key }}</h6>
10+
<div class="card col-12">
11+
<div class="card-body pb-0">
12+
<ul class="list-unstyled">
13+
@foreach($values as $notification)
14+
<li>
15+
@include('notification')
16+
</li>
17+
@endforeach
18+
</ul>
19+
</div>
20+
</div>
21+
</div>
22+
@empty
23+
<div class="text-center">
24+
No Notifications
25+
</div>
26+
@endforelse
27+
</div>
28+
@endsection

routes/web.php

+1
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@
3434

3535
Route::get('/notifications/recent', 'NotificationController@getRecentNotifications');
3636
Route::get('/notifications/mark-read/{notificationId}', 'NotificationController@markRead');
37+
Route::get('/all-notifications', 'NotificationController@viewAll');
3738
});

0 commit comments

Comments
 (0)