diff --git a/app/Http/Controllers/BookingController.php b/app/Http/Controllers/BookingController.php index a24941b8..45912b3c 100644 --- a/app/Http/Controllers/BookingController.php +++ b/app/Http/Controllers/BookingController.php @@ -13,7 +13,7 @@ use App\Invoice; use App\SettingCredit; use App\SettingTaxRate; use App\SettingBillingCharge; -use App\Notification; +use App\Notifications\BookingUpdated; use Auth; use Validator; use DateTime; @@ -97,7 +97,9 @@ class BookingController extends Controller $booking->status_desc = $status_desc; $booking->marking = $booking->user->marking; } - + + $user->notify(new BookingUpdated($booking)); + return $bookings; } diff --git a/app/Notifications/BookingUpdated.php b/app/Notifications/BookingUpdated.php new file mode 100644 index 00000000..b436f456 --- /dev/null +++ b/app/Notifications/BookingUpdated.php @@ -0,0 +1,72 @@ +booking = $booking; + } + + /** + * Get the notification's delivery channels. + * + * @param mixed $notifiable + * @return array + */ + public function via($notifiable) + { + return ['database', 'broadcast']; + } + + // /** + // * Get the mail representation of the notification. + // * + // * @param mixed $notifiable + // * @return \Illuminate\Notifications\Messages\MailMessage + // */ + // public function toMail($notifiable) + // { + // return (new MailMessage) + // ->line('The introduction to the notification.') + // ->action('Notification Action', url('/')) + // ->line('Thank you for using our application!'); + // } + + public function toDatabase($notifiable) + { + return [ + 'booking_id' => $this->booking->id + ]; + } + + /** + * Get the array representation of the notification. + * + * @param mixed $notifiable + * @return array + */ + public function toArray($notifiable) + { + return [ + 'booking' => $this->booking, + ]; + } + +} diff --git a/resources/assets/js/components/Navbar.vue b/resources/assets/js/components/Navbar.vue index 9095f148..516ecad8 100644 --- a/resources/assets/js/components/Navbar.vue +++ b/resources/assets/js/components/Navbar.vue @@ -108,7 +108,7 @@ export default { pagination: [], }), mounted () { - //this.listen() + this.listen() }, computed: mapGetters({ user: 'auth/user' @@ -191,13 +191,22 @@ export default { Authorization: 'Bearer ' + localStorage.getItem("token") }, }, - }); - console.log(this.user.id) - window.Echo.private('App.User.' + this.user.id) - .notification((notification) => { - console.log(notification); - }); + + // window.Echo.channel('private-App.User.' + this.user.id) + // .listen((notification) => { + // console.log(notification); + // }); + + // window.Echo.channel('private-App.User.' + this.user.id) + // .listen('BroadcastNotificationCreated', response => { + // if (! ('Notification' in window)) { + // alert('Web Notification is not supported'); + // return; + // } + // console.log(response) + + // }); },