Snippet unlited
6 months ago
            use App\Jobs\MailSender;
use App\Jobs\SmsSender;
use App\Jobs\MailJob;
use App\Jobs\SmsJob;

class TestController extends Controller 
{
      public function test() {
            MailSender::dispatch(new MailJob($to, $message, etc, etc));
            ...
            SmsSender::dispatch(new SmsJob($to, $message, etc, etc));
     }
}

...

class MailSender implements ShouldQueue 
{
       private $mailJob;
       
       public function __construct(MailJob $mailJob) 
       {
             $this->mailJob = $mailJob;
       } 
       public function handle(Mail $mail) 
       {
             $mail->to($this->mailJob->to);
             ...
             $mail->send($message);
       }
}

class MailJob {
     public $to;
     public $message;
     ....
}
        
add