Laravel Email, Queue & Jobs
Send Email Through Jobs and queue
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.
📝Edit: SendPasswordResetLink
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