FacebookPost.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace App\Notifications;
  3. use Illuminate\Bus\Queueable;
  4. use Illuminate\Contracts\Queue\ShouldQueue;
  5. use Illuminate\Notifications\Messages\MailMessage;
  6. use Illuminate\Notifications\Notification;
  7. use NotificationChannels\FacebookPoster\FacebookPosterChannel;
  8. use NotificationChannels\FacebookPoster\FacebookPosterPost;
  9. class FacebookPost extends Notification
  10. {
  11. use Queueable;
  12. /**
  13. * Create a new notification instance.
  14. *
  15. * @return void
  16. */
  17. public function __construct()
  18. {
  19. //
  20. }
  21. /**
  22. * Get the notification's delivery channels.
  23. *
  24. * @param mixed $notifiable
  25. * @return array
  26. */
  27. public function via($notifiable)
  28. {
  29. return [FacebookPosterChannel::class];
  30. //return ['mail'];
  31. }
  32. /**
  33. * Get the mail representation of the notification.
  34. *
  35. * @param mixed $notifiable
  36. * @return \Illuminate\Notifications\Messages\MailMessage
  37. */
  38. public function toMail($notifiable)
  39. {
  40. return (new MailMessage)
  41. ->line('The introduction to the notification.')
  42. ->action('Notification Action', url('/'))
  43. ->line('Thank you for using our application!');
  44. }
  45. /**
  46. * Get the array representation of the notification.
  47. *
  48. * @param mixed $notifiable
  49. * @return array
  50. */
  51. public function toArray($notifiable)
  52. {
  53. return [
  54. //
  55. ];
  56. }
  57. public function toFacebookPoster($notifiable) {
  58. $url = url(env('APP_URL') . "/" . $notifiable->slug);
  59. //$title = $notifiable->title;
  60. //$title = str_replace("’", "'", $title);
  61. //$title = str_replace('“', "'", $title);
  62. $text = $notifiable->title;
  63. return (new FacebookPosterPost($text))->withLink($url);
  64. }
  65. }