NathanGeerinck /
laravel-newsletter
| 1 | <?php |
||
| 2 | |||
| 3 | namespace App\Jobs; |
||
| 4 | |||
| 5 | use Mail; |
||
| 6 | use App\Models\User; |
||
| 7 | use App\Mail\ListImported; |
||
| 8 | use App\Models\MailingList; |
||
| 9 | use Illuminate\Bus\Queueable; |
||
| 10 | use Illuminate\Queue\SerializesModels; |
||
| 11 | use Illuminate\Queue\InteractsWithQueue; |
||
| 12 | use Illuminate\Contracts\Queue\ShouldQueue; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * Class ImportSubscriptions. |
||
| 16 | * @property User user |
||
| 17 | * @property MailingList list |
||
| 18 | */ |
||
| 19 | class ImportSubscriptions implements ShouldQueue |
||
| 20 | { |
||
| 21 | use InteractsWithQueue, Queueable, SerializesModels; |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 22 | |||
| 23 | /** |
||
| 24 | * @var MailingList |
||
| 25 | */ |
||
| 26 | protected $user; |
||
| 27 | protected $list; |
||
| 28 | protected $results; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * ImportSubscriptions constructor. |
||
| 32 | * @param User $user |
||
| 33 | * @param MailingList $list |
||
| 34 | * @param $results |
||
| 35 | */ |
||
| 36 | public function __construct(User $user, MailingList $list, $results) |
||
| 37 | { |
||
| 38 | $this->user = $user; |
||
| 39 | $this->list = $list; |
||
| 40 | $this->results = $results; |
||
| 41 | } |
||
| 42 | |||
| 43 | public function handle() |
||
| 44 | { |
||
| 45 | foreach ($this->results as $result) { |
||
| 46 | $this->list->subscriptions()->create($result); |
||
| 47 | } |
||
| 48 | |||
| 49 | if (env('NOTIFICATIONS') == true) { |
||
| 50 | Mail::to($this->user)->queue(new ListImported($this->list)); |
||
| 51 | } |
||
| 52 | } |
||
| 53 | } |
||
| 54 |