| 1 |  |  | <?php namespace JobApis\JobsToMail\Notifications; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | use Illuminate\Bus\Queueable; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | use Illuminate\Notifications\Notification; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Illuminate\Contracts\Queue\ShouldQueue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Illuminate\Queue\SerializesModels; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use JobApis\JobsToMail\Models\Search; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use JobApis\JobsToMail\Notifications\Messages\JobMailMessage; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | class JobsCollected extends Notification implements ShouldQueue | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     use Queueable, SerializesModels; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |      * @var array of Job objects | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     protected $jobs; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |      * @var Search | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     protected $search; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      * Create a new notification instance. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * @param array $jobs | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      * @param Search $search | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      * @return void | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 | 8 |  |     public function __construct(array $jobs, Search $search) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 | 8 |  |         $this->jobs = $jobs; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 | 8 |  |         $this->search = $search; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 | 8 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      * Get the notification's delivery channels. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * @param  mixed  $notifiable | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 | 1 |  |     public function via($notifiable) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 | 1 |  |         return ['mail', 'database']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      * Get the array representation of the notification for saving to the database. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      * @param  mixed  $notifiable | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 | 1 |  |     public function toArray($notifiable) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 | 1 |  |         return $this->jobs; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      * Get the mail representation of the notification. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      * @param  mixed  $notifiable | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      * @return \Illuminate\Notifications\Messages\MailMessage | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 65 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 66 | 1 |  |     public function toMail($notifiable) | 
            
                                                        
            
                                    
            
            
                | 67 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 68 | 1 |  |         $count = count($this->jobs); | 
            
                                                        
            
                                    
            
            
                | 69 | 1 |  |         $message = new JobMailMessage(); | 
            
                                                        
            
                                    
            
            
                | 70 | 1 |  |         $message->viewData['user_id'] = $notifiable->id; | 
            
                                                        
            
                                    
            
            
                | 71 | 1 |  |         $message->subject($count.' job listings found especially for you') | 
            
                                                        
            
                                    
            
            
                | 72 | 1 |  |             ->greeting('Hello,') | 
            
                                                        
            
                                    
            
            
                | 73 | 1 |  |             ->line('We found the following jobs that we think you\'ll be interested in based on your search:') | 
            
                                                        
            
                                    
            
            
                | 74 | 1 |  |             ->line("\"{$this->search->keyword}\" in \"{$this->search->location}\""); | 
            
                                                        
            
                                    
            
            
                | 75 | 1 |  |         foreach ($this->jobs as $job) { | 
            
                                                        
            
                                    
            
            
                | 76 | 1 |  |             $message->listing($job); | 
            
                                                        
            
                                    
            
            
                | 77 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 78 | 1 |  |         return $message; | 
            
                                                        
            
                                    
            
            
                | 79 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 80 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 81 |  |  |  | 
            
                        
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.