diff --git a/app/Http/Controllers/NotificationController.php b/app/Http/Controllers/NotificationController.php index 59846fee..00c8e722 100644 --- a/app/Http/Controllers/NotificationController.php +++ b/app/Http/Controllers/NotificationController.php @@ -42,8 +42,11 @@ class NotificationController extends Controller public function getUserMessage() { + $user_all_notification = Notification::Where("user_id",Auth::user()->id)->orderby('updated_at','desc')->get(); + + return response()->json([ - "message" =>Notification::Where("user_id",Auth::user()->id)->orderby('updated_at','desc')->get(), + "message" =>$user_all_notification, "unread_message" =>Notification::Where([ ["user_id",Auth::user()->id], ["is_read",0] @@ -57,4 +60,6 @@ class NotificationController extends Controller ->update(array('is_read' => 1)); return response()->json("Read message", 200); } + + } \ No newline at end of file diff --git a/app/Notification.php b/app/Notification.php index c9acda64..0ac7488f 100644 --- a/app/Notification.php +++ b/app/Notification.php @@ -7,4 +7,71 @@ use Illuminate\Database\Eloquent\Model; class Notification extends Model { protected $fillable = ['detail','user_id','is_read']; + protected $appends = ['time_interval']; + + public function getTimeIntervalAttribute() + { + $created_time = $this->created_at; + + date_default_timezone_set('Asia/Kuala_Lumpur'); //Change as per your default time + $str = strtotime($created_time); + $today = strtotime(date('Y-m-d H:i:s')); + + // It returns the time difference in Seconds... + $time_differnce = $today-$str; + + // To Calculate the time difference in Years... + $years = 60*60*24*365; + + // To Calculate the time difference in Months... + $months = 60*60*24*30; + + // To Calculate the time difference in Days... + $days = 60*60*24; + + // To Calculate the time difference in Hours... + $hours = 60*60; + + // To Calculate the time difference in Minutes... + $minutes = 60; + + if(intval($time_differnce/$years) > 1) + { + return intval($time_differnce/$years)." years ago"; + }else if(intval($time_differnce/$years) > 0) + { + return intval($time_differnce/$years)." year ago"; + }else if(intval($time_differnce/$months) > 1) + { + return intval($time_differnce/$months)." months ago"; + }else if(intval(($time_differnce/$months)) > 0) + { + return intval(($time_differnce/$months))." month ago"; + }else if(intval(($time_differnce/$days)) > 1) + { + return intval(($time_differnce/$days))." days ago"; + }else if (intval(($time_differnce/$days)) > 0) + { + return intval(($time_differnce/$days))." day ago"; + }else if (intval(($time_differnce/$hours)) > 1) + { + return intval(($time_differnce/$hours))." hours ago"; + }else if (intval(($time_differnce/$hours)) > 0) + { + return intval(($time_differnce/$hours))." hour ago"; + }else if (intval(($time_differnce/$minutes)) > 1) + { + return intval(($time_differnce/$minutes))." minutes ago"; + }else if (intval(($time_differnce/$minutes)) > 0) + { + return intval(($time_differnce/$minutes))." minute ago"; + }else if (intval(($time_differnce)) > 1) + { + return intval(($time_differnce))." seconds ago"; + }else + { + return "few seconds ago"; + } + } + } diff --git a/resources/assets/js/components/Navbar.vue b/resources/assets/js/components/Navbar.vue index bfe6afe3..8cdc5c99 100644 --- a/resources/assets/js/components/Navbar.vue +++ b/resources/assets/js/components/Navbar.vue @@ -22,7 +22,7 @@ - +
@@ -31,9 +31,13 @@ {{item.detail}} +
+ + {{item.time_interval}} +
- +
@@ -119,6 +123,7 @@ export default { this.loadingNotification=false; this.notification = response.data; this.bellBadge = this.notification.unread_message.length; + console.log(response.data); }).catch((error) => { console.log(error) this.$router.push({ @@ -130,7 +135,6 @@ export default { axios .post('/api/notification/read-notification/'+notification_id) .then((response) => { - console.log(1211); this.getNotification(); }).catch((error) => { console.log(error) @@ -157,6 +161,12 @@ export default { overflow-y: scroll; overflow-x: hidden; } +.el-dropdown-menu__item { + line-height: 26px; +} +.opacity80{ + opacity: 0.8 ; +} ::-webkit-scrollbar { width: 0px; background: transparent; /* make scrollbar transparent */