Hello developers in this tutorial we will discuss about how to add delay while sending emails in a queue
S.no | Contents-topics |
---|---|
1 | Basic env setup for sending emails |
2 | Configuration for job-queues |
3 | Making job-queues |
4 | Adding delay to job |
5 | Calling the job queues |
For sending emails we first .env file with mail credentials like mail driver , hostname,port number
For creating new job in brief you may consider JOBS IN LARAVEL 10 , JOBS-QUEUES IN LARAVEL 10 now we will create jobs table in database which stores jobs and process them one by one with FCFS( first come first serve).
Copy for creating tableCopy
It will create migration file and then we have to create this migration in our database
command for migartion Copy
This will create Jobs table in database
Now we will create our new job with name SendEmailToUser
command for job: Copy
Also read:CREATE CUSTOM ROUTE FILE IN LARAVEL 10
Now for the testing the jobs in laravel we will change the name of the users in App\Jobs\SendEmailToUser with the help of jobs , paste the following code in app/Jobs/SendEmailToUser to update the user
code for SendEmailToUserCopy
create a view welcomeMail in resources/views which will send in the mail
in .env file make QUEUE_CONNECTION=sync to QUEUE_CONNECTION=database
.env Copy
Now from controller we call this SendEmailToUser job
code: Copy
new SendEmailToUser($emails)) ->delay(now()->addSeconds(2) this method will add delay of 2 seconds in sending mail
Also read: HOW TO MAKE TRAITS IN LARAVEL 10.
0 Comments (Please let us know your query)