Advertisement
Guest User

Untitled

a guest
Sep 21st, 2019
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. ####CONTROLLER
  2.  
  3. public function sendMail()
  4. {
  5. $user = User::find(111);
  6. $data = [
  7. 'prova' => 'ciao'
  8. ];
  9. SendMailClass::sendMail($user, $data, EmailEnumerators::sign_up_email);
  10. }
  11.  
  12.  
  13. #####CLASSE
  14.  
  15. public static function sendMail($user, $data, $type){
  16. Mail::to('battiatosimone67@gmail.com')
  17. ->queue(new SendCentralMail($user, $data, $type));
  18. }
  19.  
  20.  
  21. #####MAILABLE
  22.  
  23. <?php
  24.  
  25. namespace App\Mail;
  26.  
  27. use Illuminate\Bus\Queueable;
  28. use Illuminate\Mail\Mailable;
  29. use Illuminate\Queue\SerializesModels;
  30.  
  31. class SendCentralMail extends Mailable
  32. {
  33. use Queueable, SerializesModels;
  34.  
  35.  
  36. public $user;
  37. protected $data;
  38. protected $type;
  39.  
  40. public function __construct($user, $data, $type)
  41. {
  42. $this->user = $user;
  43. $this->data = $data;
  44. $this->type = $type;
  45. }
  46.  
  47. /**
  48. * Build the message.
  49. *
  50. * @return $this
  51. */
  52. public function build()
  53. {
  54. return $this->from('info@mystoryviewer.com', 'MSV')
  55. ->subject('Subject')
  56. ->view('mail.'.$this->type)
  57. ->with([
  58. 'nome' => $this->user->name,
  59. 'cognome' => $this->user->surname,
  60. 'prova' => $this->data['prova']
  61. ]);
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement