diff --git a/.env-example b/.env-example index 4271cefe..5c17b459 100644 --- a/.env-example +++ b/.env-example @@ -13,11 +13,6 @@ DB_DATABASE=default DB_USERNAME=default DB_PASSWORD=secret -BROADCAST_DRIVER=log -CACHE_DRIVER=file -SESSION_DRIVER=file -SESSION_LIFETIME=120 -QUEUE_DRIVER=sync REDIS_HOST=127.0.0.1 REDIS_PASSWORD=null diff --git a/app/Events/RateUpdated.php b/app/Events/RateUpdated.php new file mode 100644 index 00000000..58f49817 --- /dev/null +++ b/app/Events/RateUpdated.php @@ -0,0 +1,47 @@ +rate = $rate; + } + + /** + * Get the channels the event should broadcast on. + * + * @return \Illuminate\Broadcasting\Channel|array + */ + public function broadcastOn() + { + return new Channel('rate-updated'); + //return new PrivateChannel('rate-updated'); + } + + public function broadcastWith() { + return [ + 'rate' => $this->rate, + ]; + } + +} diff --git a/app/Notifications/RateUpdated.php b/app/Notifications/RateUpdated.php deleted file mode 100644 index 65781b64..00000000 --- a/app/Notifications/RateUpdated.php +++ /dev/null @@ -1,61 +0,0 @@ -line('The introduction to the notification.') - ->action('Notification Action', url('/')) - ->line('Thank you for using our application!'); - } - - /** - * Get the array representation of the notification. - * - * @param mixed $notifiable - * @return array - */ - public function toArray($notifiable) - { - return [ - // - ]; - } -} diff --git a/app/Observers/RateObserver.php b/app/Observers/RateObserver.php new file mode 100644 index 00000000..14e55867 --- /dev/null +++ b/app/Observers/RateObserver.php @@ -0,0 +1,21 @@ + ["auth:api"]]); + require base_path('routes/channels.php'); } } diff --git a/resources/assets/js/components/LocaleDropdown.vue b/resources/assets/js/components/LocaleDropdown.vue index 7b490660..0e411ddf 100644 --- a/resources/assets/js/components/LocaleDropdown.vue +++ b/resources/assets/js/components/LocaleDropdown.vue @@ -210,6 +210,7 @@ export default { }) }, + } } diff --git a/resources/assets/js/components/Navbar.vue b/resources/assets/js/components/Navbar.vue index e7d999fe..46544951 100644 --- a/resources/assets/js/components/Navbar.vue +++ b/resources/assets/js/components/Navbar.vue @@ -108,11 +108,6 @@ export default { computed: mapGetters({ user: 'auth/user' }), - mounted(){ - if(this.user){ - //this.getNotification(this.url) - } - }, methods: { async logout(){ // Log out the user. @@ -121,15 +116,15 @@ export default { // Redirect to login. this.$router.push({ name: 'login' }); }, - refreshNoti() { - axios.get(this.url).then(response => { - this.bookingTable = response.data.data - this.notification = response.data.message.data; - this.bellBadge = response.data.unread_message.length; - this.makePagination(response.data.message); - console.log(response.data); - }) - }, + // refreshNoti() { + // axios.get(this.url).then(response => { + // this.bookingTable = response.data.data + // this.notification = response.data.message.data; + // this.bellBadge = response.data.unread_message.length; + // this.makePagination(response.data.message); + // console.log(response.data); + // }) + // }, // getNotification(url){ // this.notification = []; // this.loadingNotification=true; @@ -191,7 +186,7 @@ export default { // }, navigateTo(nav) { window.location.href = nav; - } + } } } diff --git a/resources/assets/js/middleware/admin.js b/resources/assets/js/middleware/admin.js index f2ccc855..3a0c97b3 100644 --- a/resources/assets/js/middleware/admin.js +++ b/resources/assets/js/middleware/admin.js @@ -1,7 +1,6 @@ import store from '~/store' export default (to, from, next) => { - console.log(store.getters['auth/role']) if (store.getters['auth/role'] !== 'admin') { next({ name: 'home' }) } else { diff --git a/resources/assets/js/pages/home.vue b/resources/assets/js/pages/home.vue index c02353aa..ff154287 100644 --- a/resources/assets/js/pages/home.vue +++ b/resources/assets/js/pages/home.vue @@ -402,6 +402,8 @@ import Form from 'vform' import LoginWithGithub from '~/components/LoginWithGithub' import store from '~/store' import axios from 'axios' +import Echo from "laravel-echo" +import Pusher from "pusher-js" export default { middleware: ['auth'], @@ -526,8 +528,40 @@ export default { this.initBooking(); this.getRate(); this.getCompleteBooking(); + this.listen(); }, methods: { + // listen to update rate changes + listen(){ + window.Echo = new Echo({ + broadcaster: 'pusher', + key: '20cae353616471c0c765', + cluster: 'ap1', + encrypted: true, + auth: { + headers: { + Authorization: 'Bearer ' + localStorage.getItem("token") + }, + }, + + }); + + window.Echo.channel('rate-updated') + .listen('RateUpdated', response => { + if (! ('Notification' in window)) { + alert('Web Notification is not supported'); + return; + } + + this.$message({ + showClose: true, + message: 'New rate updated at ' + response.rate.created_at, + duration: 20000 + }); + + }); + + }, getBooking(){ let $this = this axios.get(this.url).then(response => { diff --git a/routes/channels.php b/routes/channels.php index f16a20b9..6babdff1 100644 --- a/routes/channels.php +++ b/routes/channels.php @@ -12,5 +12,5 @@ */ Broadcast::channel('App.User.{id}', function ($user, $id) { - return (int) $user->id === (int) $id; + return true; });