Advertisement
Guest User

Untitled

a guest
Mar 16th, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1. class BroadcastServiceProvider extends ServiceProvider
  2. {
  3. /**
  4. * Bootstrap any application services.
  5. *
  6. * @return void
  7. */
  8. public function boot()
  9. {
  10. Broadcast::routes();
  11.  
  12. require base_path('routes/channels.php');
  13.  
  14. /*
  15. * Authenticate the user's personal channel..
  16. */
  17. Broadcast::channel('App.user.{userId}', function ($user, $userId) {
  18. return (int) $user->id === (int) $userId;
  19. });
  20. }
  21. }
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30. public function addFriend($userRequested)
  31. {
  32. $resp = Auth::user()->addFriend($userRequested);
  33.  
  34. User::find($userRequested)->notify(new \App\Notifications\NewFriendRequest(Auth::user()) );
  35.  
  36. return $resp;
  37. }
  38.  
  39. public function acceptFriend($requester)
  40. {
  41. $resp = Auth::user()->acceptFriend($requester);
  42.  
  43. User::find($requester)->notify(new \App\Notifications\FriendRequestAccepted(Auth::user()));
  44.  
  45. return $resp;
  46. }
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59. <template>
  60. <div>
  61.  
  62. </div>
  63. </template>
  64.  
  65. <script>
  66. export default {
  67. mounted() {
  68. this.listen()
  69. },
  70. props: ['id'],
  71. methods: {
  72. listen() {
  73. window.Echo.private('App.user.' + this.id)
  74. .notification( (notification) => {
  75. alert('new notification')
  76. console.log(notification)
  77. })
  78. }
  79. }
  80. }
  81. </script>
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97. <?php
  98.  
  99. namespace App\Notifications;
  100.  
  101. use Illuminate\Bus\Queueable;
  102. use Illuminate\Notifications\Notification;
  103. use Illuminate\Contracts\Queue\ShouldQueue;
  104. use Illuminate\Notifications\Messages\MailMessage;
  105.  
  106. class NewFriendRequest extends Notification implements ShouldQueue
  107. {
  108. use Queueable;
  109.  
  110. public $user;
  111.  
  112. /**
  113. * Create a new notification instance.
  114. *
  115. * @return void
  116. */
  117. public function __construct($user)
  118. {
  119. $this->user = $user;
  120. }
  121.  
  122. /**
  123. * Get the notification's delivery channels.
  124. *
  125. * @param mixed $notifiable
  126. * @return array
  127. */
  128. public function via($notifiable)
  129. {
  130. return ['mail', 'broadcast', 'database'];
  131. }
  132.  
  133. /**
  134. * Get the mail representation of the notification.
  135. *
  136. * @param mixed $notifiable
  137. * @return \Illuminate\Notifications\Messages\MailMessage
  138. */
  139. public function toMail($notifiable)
  140. {
  141. return (new MailMessage)
  142. ->line('You receieved a new friend request from.' . $this->user->username)
  143. ->action('View their profile', route('userProfile', ['username' => $this->user->username]))
  144. ->line('Thank you for using our service!')
  145. ->line('www.Myezwin.com');
  146. }
  147.  
  148. /**
  149. * Get the array representation of the notification.
  150. *
  151. * @param mixed $notifiable
  152. * @return array
  153. */
  154. public function toArray($notifiable)
  155. {
  156. return [
  157. 'username' => $this->user->username,
  158. 'message' => 'sent you a friend request.'
  159. ];
  160. }
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement