WIP test notification

This commit is contained in:
Jack Goh
2018-08-27 14:32:02 +08:00
parent 31710d2b88
commit 3b8b988155
3 changed files with 92 additions and 9 deletions
+4 -2
View File
@@ -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;
}
+72
View File
@@ -0,0 +1,72 @@
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Broadcasting\PrivateChannel;
use App\Booking;
class BookingUpdated extends Notification
{
use Queueable;
protected $booking;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct(Booking $booking)
{
$this->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,
];
}
}
+16 -7
View File
@@ -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)
// });
},