1

I need help with Laravel Queues if someone can help me further, i have done these steps till now

  1. changed the QUEUE DRIVER in .env file to database

  2. created migrations for queue table jobs and failed-jobs

    php artisan queue:table
    php artisan queue:failed-table
    

and i have run php artisan migrate

  1. created a new Job

    php artisan make:job SendNewArticleNotification
    

Update:

Ok i have created a route /queue

Route::get('/queue', function () {

    dispatch(new \App\Jobs\SendNewArticleNotification);

});

and in my Job SendNewArticleNotification i have this

<?php

namespace App\Jobs;

use App\User;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;

class SendNewArticleNotification implements ShouldQueue
{
    use InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {

        $users = User::all();

        $article = \App\Article::first();

        foreach ($users as $user) {
            $user->notify(new \App\Notifications\Published($article));
        }    


    }
}

And when i hit my /queue route the emails are beeing sent but they are not using the database table....it takes more than 30 seconds to send 50 mails...

UPDATE

Ok i finally figured it out that dispatch() needs to be inside of a controller method because the controller has the trait dispatches jobs....and now my jobs are in queue in DB table jobs....so how do i trigger them behind the scenes?

1 Answer 1

2

Put your dispatch in your controller method and then run

php artisan queue:work
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.