Laravel Email, Queue & Jobs

Send Email Through Jobs and queue

Mosharrf Hossain
Apr 26, 2019 · 1 min read

Step: 1 — Create mail setup

we will create email for testing using Laravel Mail facade. you need to simple run bellow command.

php artisan make:mail SendPasswordResetLink

Now you will have new folder “Mail” in app directory with SendPasswordResetLink.php file. So let’s simply copy bellow code and past on that file.

Step: 2— Configuration of Queue

we will make configuration on queue driver so first of all, we will set queue driver “database”. So here define database driver on “.env” file:

QUEUE_CONNECTION=database

After that we need to generate migration and create tables for queue. So let’s run bellow command for queue database tables:

Generate Migration:

php artisan queue:table

Run Migration:

php artisan migrate

Step: 3— Create Queue Job

now we will create queue job bey following command, this command will create queue job file with Queueable. So let’s run bellow command:

php artisan make:job SendPasswordResetEmail

now you have SendPasswordResetEmailJob.php file in “Jobs” directory. So let’s see that file and put bellow code on that file.

Step: 4— Trigger the job

We can fire the job by dispatch method.

dispatch(new SendPasswordResetEmail($user, $token))

Ok now we have run another command for watch your queue process using laravel queue command, so let’s run bellow command:

php artisan queue:work

Mh Mohon

This is My blog

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store