Ad

Laravel Queue Doesnt Run As Background

- 1 answer

hi i created a laravel queue job to send mails

public function handle() {
    foreach($this->emails as $value) {
            $to         = $value->email;
            $subject    = $this->data['subject'];       
            $this->data['t_firstname']    = $value->firstname;
            $this->data['t_lastname']     = $value->lastname;
            if (view()->exists('mail.requirement_to_tutor')) {
                    $view = view('mail.requirement_to_tutor',$this->data);
                    $html = $view->render();
            }
            file_put_contents('test.txt', 'test database');
            $body = $html;
            $headers  = "From: " . $this->data['from'] . "\r\nReply-To: " . $this->data['from'] . "";
            $headers .= "MIME-Version: 1.0\r\n";
            $headers .= "Content-type: text/html; charset: utf8\r\n";
            mail($to, $subject, $body, $headers);
    }
}

and also i am pushing datas from repo

$obj = (new SendStudentRequirement($TutorsbyCity,$data));
$this->dispatch($obj);

but it doesnot run as background , the function is waiting untill the queue finish , help me out please

Ad

Answer

By default the sync driver is used. You should change this to another driver that is listed in config/queue.php

Look for the following line in your .env file and adjust to a different driver:

QUEUE_DRIVER=sync

Laravel - Docs - Queues

Ad
source: stackoverflow.com
Ad