public static function boot() { parent::boot(); static::created(function ($department_head) { $department_head->notifications()->create(['sent_to' => Employee::find($department_head->employee_id)->user->id, 'sent_by' => auth()->user()->id, 'subject' => 'New designation', 'message' => trans('notification.department_head-created', ['department' => $department_head->department->name, 'name' => auth()->user()->employee->fullName()]), 'icon' => 'institution', 'color' => 'warning']); }); }
public function notifications() { $notifications = auth()->user()->notifications()->unread()->get(); $user_notifications = collect(); foreach ($notifications as $notification) { $user_notifications->push(['subject' => $notification->subject, 'message' => $notification->message, 'object_type' => $notification->object_type, 'object_id' => value(function () use($notification) { if ($notification->object_type == 'employee') { return Employee::find($notification->object_id)->user->username; } else { return $notification->object_id; } }), 'created_at' => $notification->created_at]); } return $user_notifications; }