Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Laravel jobs dispatchNow

I have been using dispatchNow to trigger Jobs in laravel 7 but i recently switched to laravel 8 and when i try usingdispatchNow in laravel 8 things don’t work and in the editer am using it croses dispatchNow and then it says ‘dispatchNow’ is deprecated.
How can i solve this.This is my code of how am doing it.

  $job = new AccountCreatedEmailJob($user->contact, $message);
        $this->dispatchNow($job);

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

To dipatch Jobs in Laravel 8 use the following example.

  AccountCreatedEmailJob::dispatch(
    new AccountCreatedEmail($request->email, $body,$subject), $request->email);

And in your AccountCreatedEmailJob Do this

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Mail;

class AccountCreatedEmailJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public $mailable, $email;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($mailable, string $email)
    {
        $this->mailable = $mailable;
        $this->email = $email;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        Mail::to($this->email)->send($this->mailable);
    }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading