(Update) Finish Notifications System

- Can delete notifications
- Can mark single notification as read
- Can mass update all notifications as read
- Notification Title links to source
This commit is contained in:
HDVinnie
2018-01-13 23:15:27 -05:00
parent 95b767a766
commit 225e85498f
5 changed files with 112 additions and 17 deletions
@@ -0,0 +1,34 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Auth;
use App\Notifications;
use \Toastr;
use Carbon\Carbon;
class NotificationController extends Controller
{
public function get() {
$notification = Auth::user()->notifications;
return view('notification.notifications', ['notification' => $notification]);
}
public function read($id) {
Auth::user()->unreadNotifications()->findOrFail($id)->markAsRead();
return Redirect::back()->with(Toastr::success('Notification Marked As Read!', 'Yay!', ['options']));
}
public function massRead() {
$current = new Carbon();
Auth::user()->unreadNotifications()->update(['read_at' => $current]);
return Redirect::back()->with(Toastr::success('All Notifications Marked As Read!', 'Yay!', ['options']));
}
public function delete($id) {
Auth::user()->notifications()->findOrFail($id)->delete();
return Redirect::back()->with(Toastr::success('Notification Deleted!', 'Yay!', ['options']));
}
}
+10
View File
@@ -0,0 +1,10 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Notification extends Model
{
//
}
@@ -0,0 +1,59 @@
@extends('layout.default')
@section('breadcrumb')
<li>
<a href="{{ route('get_notifications') }}" itemprop="url" class="l-breadcrumb-item-link">
<span itemprop="title" class="l-breadcrumb-item-link-title">Notifications</span>
</a>
</li>
@stop
@section('content')
<div class="container box">
<div class="col-md-12 page">
<div class="header gradient teal">
<div class="inner_content">
<div class="page-title"><h1><i class="fa fa-bell-o"></i>Notifications</h1></div>
</div>
</div>
<div class="table-responsive">
<div class="pull-right"><a href="{{ route('massRead_notifications') }}"><button type="button" class="btn btn btn-success" data-toggle="tooltip" title="" data-original-title="Mark All As Read"><i class="fa fa-eye"></i> Mark All Read</button></a></div>
<table class="table table-condensed table-striped table-bordered">
<thead>
<tr>
<th>Title</th>
<th>Message</th>
<th>Date</th>
<th>Read</th>
</tr>
</thead>
<tbody>
@forelse($notification as $n)
<tr>
<td>
<a href="{{ $n->data['url'] }}" class="clearfix">
<span class="notification-title">{{ $n->data['title'] }}</span>
</a>
</td>
<td>
<span class="notification-message">{{ $n->data['body'] }}</span>
</td>
<td>
<span class="notification-ago">{{ $n->created_at->diffForHumans() }}</span>
</td>
<td>
<a href="{{ route('read_notification', array('id' => $n->id)) }}"><button type="button" class="btn btn-xxs btn-success" data-toggle="tooltip" title="" data-original-title="Mark As Read" @if($n->read_at != null) disabled @endif><i class="fa fa-eye"></i></button></a>
</td>
<td>
<a href="{{ route('delete_notification', array('id' => $n->id)) }}"><button type="button" class="btn btn-xxs btn-danger" data-toggle="tooltip" title="" data-original-title="Delete"><i class="fa fa-times"></i></button></a>
</td>
</tr>
@empty
There are no notifications found.
@endforelse
</tbody>
</table>
</div>
</div>
</div>
@stop
+2 -17
View File
@@ -17,27 +17,12 @@
</li>
<li class="dropdown hoe-rheader-submenu message-notification left-min-30">
<a href="#" class="dropdown-toggle icon-circle" data-toggle="dropdown">
<a href="{{ route('get_notifications') }}" class="dropdown-toggle icon-circle">
<i class="fa fa-bell-o"></i>
</a>
@if(Auth::user()->unreadNotifications->count() > 0)
<span class="badge badge-danger">{{ Auth::user()->unreadNotifications->count() }}</span>
@endif
</a>
<ul class="dropdown-menu ">
<li class="hoe-submenu-label">
<h3><span class="bold">{{ Auth::user()->unreadNotifications->count() }} {{ trans('pm.unread') }}</span> {{ trans('common.notifications') }} <a href="#">{{ trans('common.view-all') }}</a></h3>
</li>
<li>
@foreach(Auth::user()->unreadNotifications as $notification)
<a href="{{ $notification->data['url'] }}" class="clearfix">
<i class="fa fa-bell-o red-text"></i>
<span class="notification-title">{{ $notification->data['title'] }}</span>
<span class="notification-ago">{{ $notification->created_at->diffForHumans() }}</span>
<p class="notification-message">{{ str_limit(strip_tags($notification->data['body']), 65) }}</p>
</a>
@endforeach
</li>
</ul>
</li>
<li class="dropdown hoe-rheader-submenu message-notification left-min-30">
+7
View File
@@ -253,6 +253,13 @@ Route::group(['middleware' => 'auth'], function () {
Route::get('/graveyard', function () {
return abort(307);
})->name('graveyard');
// Notifications System
Route::get('/notifications', 'NotificationController@get')->name('get_notifications');
Route::any('/notification/read/{id}', 'NotificationController@read')->name('read_notification');
Route::any('/notification/massread', 'NotificationController@massRead')->name('massRead_notifications');
Route::any('/notification/delete/{id}', 'NotificationController@delete')->name('delete_notification');
});
/*