Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
User invitation jobs
<?php
class SendUserInvitationJob {
protected $user;
protected $tests;
function __construct(User $user, array $tests) {
$this->user = $user;
$this->tests = $tests;
}
function handle(Mailer $mailer) {
$mailer->sendTo($this->user, 'invitation');
}
}
<?php
class SendUserInvitationReminderJob extends SendUserInvitationJob {
function handle(Mailer $mailer) {
$mailer->sendTo($this->user, 'invitation reminder');
}
}
<?php
class UserController {
function postCreate(Queue $queue) {
$user = new User;
$tests = [new Test, new Test];
$queue->dispatch(new SendUserInvitationJob($user, $tests)); // instantly
$queue->dispatch((new SendUserInvitationReminderJob($user, $tests))->delay('1 week')); // later
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.